PHP code example of toxor88 / yii2-widget-switchery
1. Go to this page and download the library: Download toxor88/yii2-widget-switchery library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
toxor88 / yii2-widget-switchery example snippets
use toxor88\switchery\Switchery;
use yii\web\JsExpression;
// usage without model
echo '<label>Can do something?</label>';
echo Switchery::widget([
'name' => 'can_do_something',
'clientOptions' => [
'color' => '#64bd63',
'secondaryColor' => '#dfdfdf',
'jackColor' => '#fff',
'jackSecondaryColor' => null,
'className' => 'switchery',
'disabled' => false,
'disabledOpacity' => 0.5,
'speed' => '0.1s',
'size' => 'default',
],
'clientChangeEvent' => new JsExpression('function() {
alert("checked: " + this.checked);
}'),
]);
// usage with model
$form->model($model, 'attribute')->widget(Switchery::className(), [ /* widget options... */ ]);
// if you use the defualt ActiveField template, there can be multiple labels. To avoid it use:
// the label displays after the slider:
$form->model($model, 'attribute')->widget(Switchery::className(), [ /* widget options... */ ])->label(false);
// the label displays before the slider:
$form->model($model, 'attribute')->widget(Switchery::className(), [ 'options' => 'label' => null ])->label('label text or inherited from model');
$ php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.