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

tristate: reset only transfers indeterminate value if coming from YES #40

Open Commifreak opened 1 year ago

Commifreak commented 1 year ago

Hi.

kartik-v widgets version: 3.4.1. PHP 7.4 and Yii 2.0.47.

I have a tristate switch configured like:

$form->field( $model, 'field )->widget( SwitchInput::class, [
            'tristate' => true,
            'containerOptions' => [],
            'pluginOptions'    => [
                'offText' => "No",
                'onText'  => "Yes",
            ],
            'readonly'         => $readonly, # false in my case
        ] )->label( false );

So, initially, the switch is in middle position - ok Setting it to ON and save, transfers 1 - ok Setting it to No transfers 0 - ok

Resetting it via X while in YES state transfers '' (empty string), resulting in null inside database - ok Resetting it while in NO state transfers 0 resulting in NO - not ok.

I tried everything - only resetting while in ON state sets the form value to empty string.

I can provide a bug demo, if wanted.

Commifreak commented 1 year ago

Even worse: If reset via X and set it to YES directly after sets null actually. Weird behavior.