xutl/yii2-select2-widget

The select2 extension for the Yii framework

Installs: 1 301

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Language:JavaScript

Type:yii2-extension

1.0.0 2016-10-25 03:03 UTC

This package is auto-updated.

Last update: 2024-10-11 01:47:51 UTC


README

<?= $form->field($model, 'category_id')->widget(Select2::className(), [
            'items' => ArrayHelper::map(\common\models\Category::find()->where(['parent' => null])->asArray()->all(), 'id', 'name'),
            'clientOptions' => [
                'placeholder' => Yii::t('app', 'please choose'),
            ],
        ]) ?>

        <?= $form->field($model, 'tagValues')->widget(Select2::className(), [
            'options' => [
                'multiple' => true
            ],
            'items' => ArrayHelper::map($model->tags, 'id', 'name'),
            'clientOptions' => [
                'placeholder' => Yii::t('app', 'Add the tag you are looking for'),
                'tags' => true,
                'ajax' => [
                    'url' => Url::to(['/user/settings/auto-complete']),
                    'dataType' => 'json',
                    //延迟250ms发送请求
                    'delay' => 250,
                    'cache' => true,
                    'data' => new \yii\web\JsExpression('function (params) {
                        return {
                            query: params.term
                        };
                    }'),
                    'processResults' => new \yii\web\JsExpression('function (data) {
                        return {
                            results: data
                        };
                    }'),
                ],
            ],
        ]) ?>