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

Is there `checked` state? #5

Closed antonkomarev closed 10 years ago

antonkomarev commented 10 years ago

Hello! Thank you for the very useful widget.

I'm trying to use it and got an issue. Widget always loading in YES state.

If attribute value = 0 switch is loading in YES position. If you want to update attribute to value = 1 you must click on switch (it will be changed to NO position) and then click on it again (it will be changed back to YES position). Only after that new value will be assigned.

// Note: I've looked the code and haven't found any checked state checks in it. It looks like such functionality exists in similar widget: https://github.com/2amigos/yii2-switch-widget

I've tried 'pluginOptions' => [ 'state' => false ] but it isn't helping too.

And here is my code from DetailView widget:

[
    'attribute' => 'yes',
    'format' => 'raw',
    'type'=>DetailView::INPUT_SWITCH,
    'widgetOptions'=>[
        'pluginOptions'=>[
            'state' => false,
            'onText'=>'Yes',
            'offText'=>'No',
            'onColor' => 'success',
            'offColor' => 'danger',
        ]
    ],
    'value'=>$model->active ?
        '<span class="label label-success">Yes</span>' :
        '<span class="label label-danger">No</span>',
],  
kartik-v commented 10 years ago

This is fixed via this commit and latest release v1.2.0 in yii2-krajee-base.

Upgrade your packages via composer and retry.

antonkomarev commented 10 years ago

Fix is not helped :( Do I need to provide any additional info?

kartik-v commented 10 years ago

Not sure if your packages are updated OR you are doing it the right way.

Check the demos page and navigate to the basic usage section. The first and third examples use an initial value (the first example with model and the third without a model).

antonkomarev commented 10 years ago

Here is is my composer require section:

    "kartik-v/yii2-detail-view": "dev-master",
    "kartik-v/yii2-widgets": "*"

I've checked files and can see that files are updated with your fix. Could it happen if I'm using this widget in DetailView? It is working when I'm using this widget standalone.