kak/select2

为 Yii2 量身定制的 select2 小部件

1.0.1 2023-07-04 17:19 UTC

This package is auto-updated.

Last update: 2024-09-04 20:06:04 UTC


README

Select2 小部件 for Yii2

预览

安装

安装此扩展的首选方法是通过 composer.

运行以下命令之一

php composer.phar require --prefer-dist kak/select2 "dev-master"

或者在您的 composer.json 文件的 require 部分添加以下内容

"kak/select2": "dev-master"

to

使用方法

扩展安装完成后,只需在代码中按以下方式使用即可

<?= \kak\widgets\select2\Select2::widget([
   'toggleEnable' => false,            // visible select all/unselect all
   'selectLabel' => 'select all',
   'unselectLabel' => 'unselect all',
   'options' => [
        'data-scroll-height' => 150,  // auto scroll
        'data-item-width'    => 100,  // 100|auto
   ]
   'multiple' => true,
   'value' => ['val1','val2'],
   'name' => 'inputName',
   'items' => [
        'val1' => 'options1',
        'val2' => 'options2',
        'val3' => 'options3',
        'val4' => 'options4',
   ],
]); ?>
<?= $form->field($model, 'list')->widget('\kak\widgets\select2\Select2', [
    'items' => [
        'val1' => 'options1',
        'val2' => 'options2',
        'val3' => 'options3',
        'val4' => 'options4',
    ],
    'options' => [
        'class' => 'myCssClass'
    ],
    'clientOptions' => [],   // js options select2
]) ?>