Updating bootstrap alerts

If I update something why the bootstrap alert doesn’t change?

For example in my form if it’s ‘On Going’ then the bootstrap alert is ‘info’ when I update it to ‘Done’ then the boostrap alert will be ‘success’

But when I update and change it to ‘Done’ it is still on ‘info’ bootstrap alert.

Here’s my index code


'rowOptions' => function($model)

        {

            if($model->request_status == 'Done')

            {

                return['class' => 'success'];

            } else if($model->request_status == 'On Going')

            {

                return['class' => 'info'];

            } else if($model->request_status == 'Cancelled')

            {

                return['class' => 'danger'];

            } else if($model->request_status == 'High Priority')

            {

                return['class' => 'warning'];

            }

the _form


  <?= $form->field($model, 'request_status')->dropDownList(['On Going' => 'On Going', 'Done' => 'Done', 'Cancelled' => 'Cancelled', 'High Priority' => 'High Priority'], ['style' => 'width:200px']) ?>

What you have should work you might have spelling issue or maybe an evaluation issue. I’d recommend using constants to define the values to help spelling and other issues from having to type it over and over. I’d also recommend a switch case for your evaluation function. I believe in your case it would be easier to read and maintain





'rowOptions' => function ($model) {

        switch ($model->request_status) {

            case 'Done':

                $class = 'success';

                break;

            case 'On Going':

                $class = 'info';

                break;

            case 'Cancelled':

                $class = 'danger';

                break;

            case 'High Priority':

                $class = 'warning';

                break;

            default:

                $class = '';

        }

        return ['class' => $class];

    },



If you used const

model




const CONST_CANCELLED = 'Cancelled';

const CONST_DONE = 'Done';    

const CONST_HIGH_PRIORITY = 'High Priority';

const CONST_ON_GOING = 'On Going';



form




$form->field($model, 'request_status')->dropDownList([$model::CONST_ON_GOING => $model::CONST_ON_GOING, $model::CONST_DONE => $model::CONST_DONE, $model::CONST_CANCELLED =>  $model::CONST_CANCELLED,  $model::CONST_HIGH_PRIORITY => $model::CONST_HIGH_PRIORITY], ['style' => 'width:200px']) 



index





'rowOptions' => function ($model) {

        switch ($model->request_status) {

            case $model::CONST_DONE:

                $class = 'success';

                break;

            case $model::CONST_ON_GOING:

                $class = 'info';

                break;

            case $model::CONST_CANCELLED:

                $class = 'danger';

                break;

            case  $model::CONST_HIGH_PRIORITY:

                $class = 'warning';

                break;

            default:

                $class = '';

        }

        return ['class' => $class];

    },



if you don’t have a default class you can make the high priority one default and remove the current default