Change User Status From SwitchInput into Dropdown list

Hi all,

Currently, I have an existing code to show user status as ‘Inactive’ or ‘Active’ based on ban_time field of table User. When status of User is ‘Inactive’, the ban_time field will be updated by current timespan (I guess it use external wrapper plugin)


$form->field($user, 'ban_time')->widget(SwitchInput::classname(), [

                'type' => SwitchInput::CHECKBOX,

                'containerOptions' => ['class' => 'inner-form-group'],

                'pluginOptions' => [

                    'state' => empty($user->ban_time),

                    'handleWidth' => 60,

                    'onText' => 'Active',

                    'offText' => 'Inactive'

                ],

                'pluginEvents' => [

                    "switchChange.bootstrapSwitch" => "function(event, state) { $('[name=\'User[ban_time]\']').val(state ? 0 : 1) }",

                ]

            ])->label('Status'); 

Now, I need to add more status instead of ‘Inactive’ or ‘Active’. So I want to change this field into dropDownList but when changing status of User, ban_time was not changed


$form->field($user, 'ban_time')->dropDownList(

                [empty($user->ban_time) =>'Active', !empty($user->ban_time) =>'Inactive']

            )->label('Status'); 

Please help me how to change it

First U should check what is DB setup for this ban_time field ?

Than check if model has any errors on save?

1 Like