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
Requires
- php: >=5.4.0
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-11-11 02:00:35 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
};
}'),
],
],
]) ?>