xpbl4 / yii2-dependent-widget
依赖下拉小部件允许创建简单的下拉列表
v1.0.2
2023-07-02 22:16 UTC
Requires
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2024-09-30 01:49:09 UTC
README
依赖下拉小部件允许创建依赖下拉列表
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require --prefer-dist xpbl4/yii2-dependent-widget "*"
或者
"xpbl4/yii2-dependent-widget": "*"
将以下内容添加到您的 composer.json
文件的 require 部分中。
用法
安装扩展后,只需在代码中使用它即可
<?= Html::dropDownList('depend_field', '', ['first', 'second', 'third']); ?> <?= \xpbl4\dependent\Dropdown::widget([ 'id' => 'exampleInput', 'name' => 'test', 'items' => ['one', 'two', 'three'], 'options' => ['class' => 'form-control', 'prompt' => 'Select item...'], 'pluginOptions' => [ 'url' => \yii\helpers\Url::toRoute(), /* return [items...] */ 'initialize' => true, 'depends' => [ 'depend_id' => 'depend_field', ], 'ajaxOptions' => [ 'delay' => 500 ], 'pagination' => [ 'limit' => 10 ], ], 'pluginEvents' => [ 'dependent:init' => new \yii\web\JsExpression('consoleEvent'), 'dependent:change' => new \yii\web\JsExpression('consoleEvent'), 'dependent:focus' => new \yii\web\JsExpression('consoleEvent'), 'dependent:beforeSend' => new \yii\web\JsExpression('consoleEvent'), 'dependent:success' => new \yii\web\JsExpression('consoleEvent'), 'dependent:error' => new \yii\web\JsExpression('consoleEvent'), 'dependent:afterChange' => new \yii\web\JsExpression('consoleEvent'), ] ]); ?> <?= \xpbl4\dependent\Select2::widget([ 'id' => 'exampleInput', 'name' => 'test', 'items' => ['one', 'two', 'three'], 'options' => ['class' => 'form-control', 'prompt' => 'Select item...'], 'pluginOptions' => [ 'url' => \yii\helpers\Url::toRoute(), /* return [items...] */ 'initialize' => true, 'depends' => [ 'depend_id' => 'depend_field', ], 'ajaxOptions' => [ 'delay' => 500 ], 'pagination' => [ 'limit' => 10 ], ], 'pluginEvents' => [ 'dependent:init' => new \yii\web\JsExpression('consoleEvent'), 'dependent:change' => new \yii\web\JsExpression('consoleEvent'), ... 'select2:open' => 'function (e) { log("select2:open", e); }', 'select2:close' => new JsExpression('function (e) { log("select2:close", e); }') ... ], 'select2Options' => [ 'allowClear' => true, 'closeOnSelect' => false, ... /* Options for Select2 plugin */ ] ]); ?>