Menggunakan Yii2 Kartik Select2 pada ActiveForm

Berikut ini contoh penggunaan Select2 pada komponen ActiveForm

<?php $form = ActiveForm::begin(['type'=>ActiveForm::TYPE_HORIZONTAL]);
echo Form::widget([
    'model' => $model,
    'form' => $form,
    'columns' => 1,
    'attributes' => [

'alamat'=>['type'=> Form::INPUT_TEXTAREA,
      'options'=>['placeholder'=>'Enter Alamat...','rows'=> 6]],
 'model_soal_id'=>
     [
         'type'=>Form::INPUT_WIDGET,
         'widgetClass'=>'kartik\widgets\Select2',
         'options' => [
             'data' => ArrayHelper::map(
               Kota::find()->orderBy('nama')->asArray()->all(), 'id', 'nama'),
             'options' => ['placeholder' => Yii::t('app','Pilih Kota')],
             'pluginOptions' => [
                 'allowClear' => true
             ],
         ],
     ],
    ]
    ]);
 ActiveForm::end(); ?>
</div>

Post a Response