kartik-v / yii2-widgets

Collection of useful widgets for Yii Framework 2.0
http://demos.krajee.com/widgets
Other
558 stars 177 forks source link

[SwitchInput] "init.bootstrapSwitch" plugin event is not registered properly #355

Closed Wirone closed 2 years ago

Wirone commented 6 years ago

I want to display SwitchInput in DetailView with custom init event handler:

DetailView::widget([
    'id' => 'my-switch-input',
    'model' => $model,
    'enableEditMode' => true,
    'mode' => DetailView::MODE_EDIT,
    'attributes' => [
        [
            'attribute' => 'myFlag',
            'type' => DetailView::INPUT_SWITCH,
            'widgetOptions' => [
                'pluginEvents' => [
                    'init.bootstrapSwitch' => 'function () {
                        console.log('INIT!');
                    }',
                ]
            ],
            'format' => 'raw',
            'value' => $model->myFlag,
        ],
    ],
])

and I get in document's head:

window.bootstrapSwitch_15aea556 = { /* rendered options */ };

and in footer:

jQuery("#my-switch-input").bootstrapSwitch(bootstrapSwitch_15aea556);
jQuery("#my-switch-input").on('init.bootstrapSwitch', function (a, b, c) {
    console.log(this, a, b, c);
});

The problem is that init.bootstrapSwitch event is triggered at the very end of BootstrapSwitch (constructor) - it means it's fired just before my handler is registered.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/55657241-switchinput-init-bootstrapswitch-plugin-event-is-not-registered-properly?utm_campaign=plugin&utm_content=tracker%2F530581&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F530581&utm_medium=issues&utm_source=github).