kak / input-switch
为Yii2的bootstrap switch
dev-master
2015-12-14 16:09 UTC
Requires
- bower-asset/bootstrap-switch: >=3.3.2
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-09-22 04:40:41 UTC
README
为Yii2的bootstrap-switch小部件
文档
- @docs 选项 http://www.bootstrap-switch.org/options.html
- @docs 方法 http://www.bootstrap-switch.org/methods.html
- @docs 事件 http://www.bootstrap-switch.org/events.html
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist kak/input-switch "dev-master"
或者
"kak/input-switch": "dev-master"
将其添加到您的 composer.json
文件的 require 部分。
用法
ActiveForm
echo $form->field($model, 'list')->widget('\kak\widgets\InputSwitch\InputSwitch', [ 'options' => [ 'data-id' => $model->id, 'data-size' => 'small' ], ]) ?>
原生
echo \kak\widgets\InputSwitch\InputSwitch::widget([ 'name' => 'OperatorSwitch[' . $model->id . ']', 'value' => $model->status == true, 'options' => [ 'data-id' => $model->id, 'data-size' => 'small' ] ]);
使用事件
$js =<<<JS $('.InputSwitch').on('switchChange.bootstrapSwitch', function(event, state) { $.post('/finance/credit-operator-switch',{status: state, id: $(this).data('id') }) }); JS; $this->registerJs($js) ?>