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

Initial value with model always 'off' #31

Closed jonny7 closed 6 years ago

jonny7 commented 6 years ago

Having a little trouble with this. My model has a field that takes Y and N. But my switch always says OFF, even though the value in the $model is Y. I can't set it explicitly either. What am I doing wrong.

$form->field($personPhoneRecord->personPhone, 'PRIMARY')->widget(SwitchInput::classname(), [                    
                    'options' => [ 'id' => 'phone'],
                    'value' => true,
                    'pluginOptions' => ['size' => 'mini','onColor' => 'success', 'offColor' => 'danger']
                ]); 
jonny7 commented 6 years ago

Using this to set the value before called switchInput

$var = $personPhoneRecord->personPhone['PRIMARY'] = ( ( $personPhoneRecord->personPhone['PRIMARY'] == 'Y') ? true : false);