alexeevdv/yii2-bootstrap-toggle

2.0.0 2018-07-16 05:08 UTC

This package is auto-updated.

Last update: 2024-08-29 04:31:27 UTC


README

Build Status codecov PHP 5.6 PHP 7.0 PHP 7.1 PHP 7.2

Yii2 扩展,用于渲染 bootstrap toggle 小部件,而不是复选框。

Screenshot

安装

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

运行以下命令之一:

$ php composer.phar require alexeevdv/yii2-bootstrap-toggle "~2.0"

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

"alexeevdv/yii2-bootstrap-toggle": "~2.0"

to the require section of your composer.json file.

使用方法

在活动表单中

use alexeevdv\yii\BootstrapToggleWidget;

//...
echo $form->field($model, 'attribute')->widget(BootstrapToggleWidget::class);
//...

独立小部件

use alexeevdv\yii\BootstrapToggleWidget;

//...
BootstrapToggleWidget::widget([
    'name' => 'is_enabled',
    'value' => false,
]);
//...

选项

BootstrapToggleWidget::widget([
    /**
     * Wrapper tag name. If set to false no tag will be rendered
     */
    'container' => 'div',

    /**
     * Wrapper HTML attributes
     */
    'containerOptions' => [],
    
    /**
     * Label when checkbox is checked
     */
    'labelEnabled' => 'Yes',
    
    /**
     * Label when checkbox is not checked
     */
    'labelDisabled' => 'No',
     
    /**
     * Value when checkbox is checked
     */
    'valueEnabled' => '1',

    /**
     * Value when checkbox is not checked
     */
    'valueDisabled' => '0',     
     
     /**
      * Additional javascript options to Bootstrap Toggle plugin 
      */
     'pluginOptions' => [],
]);