yii2-chosen Chosen widget for Yii2 (with Bootstrap3)

Chosen + Bootstrap 3 + Yii2

  1. Credits
  2. Installation
  3. Usage
  4. Resources

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

1 0
6 followers
0 downloads
Yii Version: 2.0
License: BSD-2-Clause
Category: User Interface
Developed by: RomeroMsk
Created on: May 30, 2014
Last updated: 10 years ago

Related Extensions