0
votes

Im using Kartik DepDrop widget in my Yii2 project. When I use it within an ActiveForm, as showed in documentation, everything works fine. The issue is that Im coding a custom form in HTML and I need to use the widget. Is this possible or I need to write custom AJAX function?

1

1 Answers

0
votes

Please take a look at the demos @ http://demos.krajee.com/widget-details/select2

You can use Select2 without ActiveForm and even without Model. From the demo examples, below is relevant code snippet:

use kartik\widgets\Select2

// With a model and without ActiveForm
echo Select2::widget([
    'model' => $model,
    'attribute' => 'state_2',
    'data' => $data,
    'options' => ['placeholder' => 'Select a state ...'],
    'pluginOptions' => [
        'allowClear' => true
    ],
]);

// Without model and implementing a multiple select
echo '<label class="control-label">Provinces</label>';
echo Select2::widget([
    'name' => 'state_10',
    'data' => $data,
    'options' => [
        'placeholder' => 'Select provinces ...',
        'multiple' => true
    ],
]);