I am trying to make DropDownList
readonly or disable in form for update condition but my code is not working ...
echo $form->dropDownListRow($model, 'sem_id', CHtml::listData(Sem::model()->findAll(), 'id', 'title'/*, array("disabled" => "disabled")*/ , array('readonly' => 'readonly') ));
Error: call_user_func() expects parameter 1 to be a valid callback, array must have exactly two members
First thing is you should dropDownList
instead of dropDownListRow
. Also you forgot to use )
after 'title'
And you should use "disabled" => "disabled"
instead of 'readonly' => 'readonly'
. I don't think they have a readonly attribute in html tags.
echo $form->dropDownList($model, 'sem_id', CHtml::listData(Sem::model()->findAll(), 'id', 'title'), array("disabled" => "disabled"));
This can make disabled dropdown list, but note that you can't relay on html attributes. Because the users can remove this attribute easily and can change dropdown value. So you need to have a control on your server.
Working example of Yii 2 dropdown disable:
<?=
$form->field($model, 'customer_status')->dropDownList([
'0' => 'Requested',
'1' => 'Registered',
'3' => 'Un-Rgistered',
'2' => 'Disabled'
], ['disabled' => 'disabled'])
?>