'how can I make the DropDownList be blocked along with the button?

how can I make the DropDownList be blocked along with the button? please

        [
            'attribute' => 'user_id',
            'format' => 'raw',
            'value' => (Html::dropDownList(
                    'user_id', $model['user_id'], ArrayHelper::map($users, 'id', function ($user) {
                    if ($user)
                        return $user->profile->secondname . ' ' . $user->profile->firstname;
                }), ['class' => 'form-control', 'style' => 'width: 200px; display: inline-block;', 'onchange' => (new JsExpression('$("#user_id").data("params", {"user_id": this.value});'))]) .
                ' ' . Html::a('BUTTON', [
                    'assign-user',
                    'id' => $model->id
                ], [
                    'id' => 'user_id',
                    'class' => 'btn btn-primary btn-xs',
                    'disabled' => $model->status == 0 ? null : true,
                    'onclick'=> new JsExpression('return false;'),
                    'data' => ['method' => 'post', 'params' => ['user_id' => null]]
                ]))
        ],

the button is blocked, but because of the drop-down list, you can still click on it



Solution 1:[1]

since you are using 'bootstrap', modify the code as follows:

  • Use the disabled class to disable the 'button'(tag a).

  • Use 'disabled' => true to disable 'dropDownList'.

    [
             'attribute' => 'user_id',
             'format' => 'raw',
             'value' => (Html::dropDownList(
                     'user_id', $model['user_id'], ArrayHelper::map($users, 'id', function ($user) {
                     if ($user)
                         return $user->profile->secondname . ' ' . $user->profile->firstname;
                 }), ['disabled' =>  $model->status == 0 ? null : true,'class' => 'form-control', 'style' => 'width: 200px; display: inline-block;', 'onchange' => (new JsExpression('$("#user_id").data("params", {"user_id": this.value});'))]) .
                 ' ' . Html::a('BUTTON', [
                     'assign-user',
                     'id' => $model->id
                 ], [
                     'id' => 'user_id',
                     'class' => $model->status == 0 ? 'btn btn-primary btn-xs' : 'btn btn-primary btn-xs disabled',
                    // 'disabled' => $model->status == 0 ? null : true, // Optional
                     'onclick'=> new JsExpression('return false;'),
                     'data' => ['method' => 'post', 'params' => ['user_id' => null]]
                 ]))
    ],
    

Good luck.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1