kartik-v / yii2-widget-switchinput

A Yii2 wrapper widget for the Bootstrap Switch plugin to use checkboxes & radios as toggle switches (sub repo split from yii2-widgets)
Other
38 stars 11 forks source link

Animate issue #20

Closed PMan2 closed 8 years ago

PMan2 commented 8 years ago

When you want to turn off animation, you can set 'animate' attribute in 'pluginOptions' to false:

echo $form->field($model, 'status')->widget(SwitchInput::classname(), [
    'pluginOptions' => [
        'animate' => false
    ]
]);

But it's not working, animate is still set to true in web page source code

<script type="text/javascript">
    var bootstrapSwitch_29bf9f81 = {"animate":true,"indeterminate":false,"disabled":false,"readonly":false};
</script>

It's because you are using empty() PHP function to check, whether value of 'animate' is valid:

// SwitchInput.php, row 188
if (empty($this->pluginOptions['animate'])) {
    $this->pluginOptions['animate'] = true;
}

Problem is that empty() returns true also on boolean value false of 'animate', I suggest additional test whether value is type of boolean or not:

// SwitchInput.php, row 188 (FIXED)
if (empty($this->pluginOptions['animate']) && !is_bool($this->pluginOptions['animate'])) {
    $this->pluginOptions['animate'] = true;
}

After this fix it's working correctly. Thanks for your cool plugins!