项目作者: 2amigos

项目描述 :
Bootstrap Switch Widget for Yii2
高级语言: PHP
项目地址: git://github.com/2amigos/yii2-switch-widget.git
创建时间: 2014-04-02T12:07:22Z
项目社区:https://github.com/2amigos/yii2-switch-widget

开源协议:Other

下载


Bootstrap Switch Widget for Yii2

Latest Version
Software License
Build Status
Coverage Status
Quality Score
Total Downloads

Renders a Bootstrap Toggle Switch plugin widget.

Installation

The preferred way to install this extension is through composer.

Either run

  1. $ composer require 2amigos/yii2-switch-widget:~1.0

or add

  1. "2amigos/yii2-switch-widget": "~1.0"

to the require section of your composer.json file.

Usage

The widget comes in two flavors:

  • SwitchBox
  • SwitchRadio

SwitchBox

This widget renders a Bootstrap Toggle Switch Checkbox input control. Best suitable for attributes with boolean states (on|off, true|false, 1|0) when used with model.

Example of use with a form

  1. <?php
  2. use dosamigos\switchinput\SwitchBox;
  3. ?>
  4. <?= $form->field($model, 'validated')->widget(SwitchBox::className(),[
  5. 'clientOptions' => [
  6. 'size' => 'large',
  7. 'onColor' => 'success',
  8. 'offColor' => 'danger'
  9. ]
  10. ]);?>

Example of use without a model

  1. <?= \dosamigos\switchinput\SwitchBox::widget([
  2. 'name' => 'Test',
  3. 'checked' => true,
  4. 'clientOptions' => [
  5. 'size' => 'large',
  6. 'onColor' => 'success',
  7. 'offColor' => 'danger'
  8. ]
  9. ]);?>

SwitchRadio

This widget renders a Bootstrap Toggle Switch Checkbox radio list control. Best suitable for attributes with multiple states when used with a model.

Example of use with a form

  1. <?php
  2. use dosamigos\switchinput\SwitchRadio;
  3. ?>
  4. <?= $form->field($model, 'status')->widget(SwitchRadio::className(), [
  5. 'items' => [
  6. 20 => 'rejected',
  7. 40 => 'approved',
  8. 50 => 'on hold'
  9. ],
  10. ]);?>

Example of use without a model

  1. <?= \dosamigos\switchinput\SwitchRadio::widget([
  2. 'name' => 'shape',
  3. 'inline' => false,
  4. 'items' => [
  5. [
  6. 'label' => 'best',
  7. 'value' => 100,
  8. 'options' => ['data-size' => 'mini']
  9. ],
  10. 20 => 'good',
  11. 40 => 'superior',
  12. 50 => 'master'
  13. ],
  14. 'labelOptions' => ['style' => 'font-size:16px']
  15. ]);?>

Not displaying the label

  1. <?= $form->field($model, 'validated')->widget(SwitchBox::className(),[
  2. 'options' => [
  3. 'label' => false
  4. ],
  5. 'clientOptions' => [
  6. 'size' => 'large',
  7. 'onColor' => 'success',
  8. 'offColor' => 'danger'
  9. ]
  10. ]);?>

Using code fixer

We have added a PHP code fixer to standardize our code. It includes Symfony, PSR2 and some contributors rules.

  1. ./vendor/bin/php-cs-fixer fix ./src --config .php_cs

Testing

  1. $ ./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The BSD License (BSD). Please see License File for more information.




Custom Software | Web & Mobile Software Development

www.2amigos.us