This repository was archived by the owner on Feb 17, 2025. It is now read-only.
File tree 3 files changed +27
-7
lines changed 3 files changed +27
-7
lines changed Original file line number Diff line number Diff line change 28
28
Once the extension is installed, simply use it in your code by :
29
29
30
30
``` php
31
- <?= \oakcms\bootstrapswitch\AutoloadExample::widget(); ?>```
31
+ <?= $form->field($model, 'field')->widget(\oakcms\bootstrapswitch\Switcher::className()) ?>
32
+ ```
33
+
34
+ Or
35
+
36
+ ``` php
37
+ <?= \oakcms\bootstrapswitch\Switcher::widget([
38
+ 'name' => 'Name',
39
+ 'checked' => true,
40
+ 'clientOptions' => [
41
+ 'size' => 'large',
42
+ 'onColor' => 'success',
43
+ 'offColor' => 'danger'
44
+ ]
45
+ ]); ?>
46
+ ```
Original file line number Diff line number Diff line change @@ -25,7 +25,11 @@ trait STrait
25
25
* Please refer to the Bootstrap Switch 3 plugin Web page for possible options.
26
26
* @see http://www.bootstrap-switch.org/
27
27
*/
28
- public $ clientOptions = [];
28
+ public $ clientOptions = [
29
+ 'size ' => 'small ' ,
30
+ 'onColor ' => 'success ' ,
31
+ 'offColor ' => 'danger '
32
+ ];
29
33
30
34
/**
31
35
* @var array the event handlers for the underlying Bootstrap Switch 3 input JS plugin.
@@ -53,6 +57,6 @@ public function registerClientScript()
53
57
$ js [] = "jQuery(' $ this ->selector ').on(' $ event', $ handler); " ;
54
58
}
55
59
}
56
- $ view ->registerJs (implode ("\n" , $ js ));
60
+ $ this -> view ->registerJs (implode ("\n" , $ js ));
57
61
}
58
62
}
Original file line number Diff line number Diff line change 33
33
34
34
class Switcher extends InputWidget
35
35
{
36
- use SwitchTrait ;
36
+ use STrait ;
37
37
38
38
/**
39
39
* @var bool whether to display the label inline or not. Defaults to true.
@@ -45,13 +45,14 @@ class Switcher extends InputWidget
45
45
*/
46
46
public function run ()
47
47
{
48
+ $ option = array_merge (['label ' => false , 'class ' => 'make-switch ' ], $ this ->options );
48
49
if ($ this ->hasModel ()) {
49
- $ input = Html::activeCheckbox ($ this ->model , $ this ->attribute , $ this -> options );
50
+ $ input = Html::activeCheckbox ($ this ->model , $ this ->attribute , $ option );
50
51
} else {
51
- $ input = Html::checkbox ($ this ->name , $ this ->checked , $ this -> options );
52
+ $ input = Html::checkbox ($ this ->name , $ this ->checked , $ option );
52
53
}
53
54
echo $ this ->inlineLabel ? $ input : Html::tag ('div ' , $ input );
54
- $ this ->selector = "# {$ this -> options ['id ' ]}" ;
55
+ $ this ->selector = "# {$ option ['id ' ]}" ;
55
56
$ this ->registerClientScript ();
56
57
}
57
58
You can’t perform that action at this time.
0 commit comments