Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alexeevdv/yii2-bootstrap-toggle

Yii2 extension to render bootstrap toggle widget instead of checkbox.
https://github.com/alexeevdv/yii2-bootstrap-toggle

bootstrap bootstrap-toggle yii2 yii2-extension yii2-widgets

Last synced: 23 days ago
JSON representation

Yii2 extension to render bootstrap toggle widget instead of checkbox.

Awesome Lists containing this project

README

        

yii2-bootstrap-toggle
===========

[![Build Status](https://travis-ci.org/alexeevdv/yii2-bootstrap-toggle.svg?branch=master)](https://travis-ci.org/alexeevdv/yii2-bootstrap-toggle)
[![codecov](https://codecov.io/gh/alexeevdv/yii2-bootstrap-toggle/branch/master/graph/badge.svg)](https://codecov.io/gh/alexeevdv/yii2-bootstrap-toggle)
![PHP 5.6](https://img.shields.io/badge/PHP-5.6-green.svg)
![PHP 7.0](https://img.shields.io/badge/PHP-7.0-green.svg)
![PHP 7.1](https://img.shields.io/badge/PHP-7.1-green.svg)
![PHP 7.2](https://img.shields.io/badge/PHP-7.2-green.svg)

Yii2 extension to render [bootstrap toggle](http://www.bootstraptoggle.com/) widget instead of checkbox.

![Screenshot](screenshot.jpg)

## Installation

The preferred way to install this extension is through [composer](https://getcomposer.org/download/).

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
```php
use alexeevdv\yii\BootstrapToggleWidget;

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

### Standalone widget

```php
use alexeevdv\yii\BootstrapToggleWidget;

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

## Options

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