alexeevdv/yii2-bootstrap-toggle

Installs: 2 711

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 1

Open Issues: 0

Type:yii2-extension

2.0.0 2018-07-16 05:08 UTC

This package is auto-updated.

Last update: 2021-09-29 01:52:09 UTC


README

Build Status codecov PHP 5.6 PHP 7.0 PHP 7.1 PHP 7.2

Yii2 extension to render bootstrap toggle widget instead of checkbox.

Screenshot

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

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

to the require section of your composer.json file.

Usage

In active form

use alexeevdv\yii\BootstrapToggleWidget;

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

Standalone widget

use alexeevdv\yii\BootstrapToggleWidget;

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

Options

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' => [],
]);