Via Composer
$ composer require wbraganca/yii2-selectivity
or add
"wbraganca/yii2-selectivity": "~2.0.1"
to the require section of your composer.json
file.
On your view file.
<?php
use wbraganca\selectivity\SelectivityWidget;
?>
<?= $form->field($model, 'city', [
'options' => ['class' => 'selectivity-container form-group']
])->widget(SelectivityWidget::classname(), [
'options' => [
'prompt' => '',
],
'pluginOptions' => [
'allowClear' => true,
'data' => ['Rio de Janeiro', 'São Paulo'],
'placeholder' => 'No city selected'
]
]) ?>
Displaying the data with appended addon
<?= $form->field($model, 'city', [
'options' => ['class' => 'selectivity-container form-group']
])->widget(SelectivityWidget::classname(), [
'options' => [
'prompt' => ''
],
'pluginOptions' => [
'allowClear' => true,
'data' => ['Rio de Janeiro', 'São Paulo'],
'placeholder' => 'No city selected'
],
'template' => '<div class="input-group">' .
'{input}' .
'<div class="input-group-append">' .
'<span class="input-group-btn">' .
'<button class="btn btn-success" type="button">' .
'<i class="fa fa-plus"></i>' .
'</button>' .
'</div>' .
'</span>' .
'</div>'
]) ?>
For more options, visit: https://arendjr.github.io/selectivity/#api