Yii2 dropDownList仅在创建模式下禁用

时间:2015-11-02 05:29:10

标签: php drop-down-menu yii2

我这样做。

<?= $form->field($model, 'HRMS_candidateStatus')->dropDownList($candidateStatus, [ 'prompt' => 'Select candidate status','class'=>'form-control input-sm',['disabled' => $model->isNewRecord] ]) ?>

我希望仅在创建模式下禁用下拉列表。我怎么能这样做?

2 个答案:

答案 0 :(得分:2)

尝试添加truedisabledfalse

<?= $form->field($model, 'HRMS_candidateStatus')->dropDownList($candidateStatus, [ 'prompt' => 'Select candidate status','class'=>'form-control input-sm',
'disabled' => $model->isNewRecord ? true : false ]) ?>

答案 1 :(得分:0)

使用已禁用的Html作为条件

<?= $form->field($model,   'HRMS_candidateStatus')->
 dropDownList($candidateStatus, [ 'prompt' => 'Select candidate status','class'=>'form-control input-sm',
['disabled' => ($model->isNewRecord) ? 'disabled' : false] ]) ?>