Yii 2.0: yii2-chosen

Chosen widget for Yii2 (with Bootstrap3)
4 followers

Chosen + Bootstrap 3 + Yii2

Credits

Installation

The preferred way to install this extension is through composer. Either run

php composer.phar require "nex/yii2-chosen" "*"

or add

"nex/yii2-chosen" : "*"

to the require section of your application's composer.json file.

Usage

With a model

<?php
use nex\chosen\Chosen;
?>
 
<?= Chosen::widget([
    'model' => $model,
    'attribute' => 'selectable_attr',
    'items' => [1 => 'First item', 2 => 'Second item', 3 => 'Third item'],
    'multiple' => true,
]);?>
 
<?= $form->field($model, 'selectable_attr')->widget(
    Chosen::className(), [
        'items' => [1 => 'First item', 2 => 'Second item', 3 => 'Third item'],
        'disableSearch' => 5, // Search input will be disabled while there are fewer than 5 items
        'clientOptions' => [
            'search_contains' => true,
            'single_backstroke_delete' => false,
        ]
]);?>

Without a model

<?php
use nex\chosen\Chosen;
?>
<?= Chosen::widget([
    'name' => 'ChosenTest',
    'value' => 3,
    'items' => [1 => 'First item', 2 => 'Second item', 3 => 'Third item'],
    'allowDeselect' => false,
    'disableSearch' => true, // Search input will be disabled
    'clientOptions' => [
        'search_contains' => true,
        'max_selected_options' => 2,
    ]
]);?>

Resources

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet