Is there a way to make an activeform item readonly? Make it have the same presentation as when it's normal, but have the input disable?
Something like this: http://demos.krajee.com/widget-details/select2 the disabled one.
Sure. In HTML it's <input type="text" readonly>
so you need to pass this option:
<?= $form->field($model, 'username', ['readonly' => true]) ?>
I had tried that, I get an exception:
Setting unknown property: yii\widgets\ActiveField::readonly
= $form->field($company, 'dot_com_name', ['readonly' => true]) ?>
first options are for the ActiveField class. Do it this way:
<?= $form->field($model, 'username')->textInput(['readonly' => true]) ?>
Thanks, that was it, I had tried the 1st option, didn't occur to me that way. :smile:
The last solution was helpful.
why is it not working in my case? I put readonly
but it is STILL editable.
echo $form->field($model, 'user_id')->widget(Select2::classname(), [
'data' => $listData,
'readonly' => true,
'options' => ['placeholder' => 'Select a Staff', 'readonly',],
'pluginOptions' => [
'readonly' => true,
'allowClear' => true,
],
])->label('Employee Name');
I think because it's widget (not standard field), it should have special option for that.
kaynewilder, may be because "readonly" has to be a key in options. Like this:
'options' => ['placeholder' => 'Select a Staff', 'readonly'=>true,],
Try put disabled :
'pluginOptions' => [
'allowClear' => true,
],
'disabled' => 'disabled'
Disabled and readonly are differing things.
Disabled element will not return on submit.
Opss..I try submit form and my element return perfectly when i use disabled!!
solution below:
<?= $form->field($model, 'yourtext')->textInput(['readonly'=>true]) ?>
If I have a dropdown list, how to make it readonly
?
<?= $form->field($model, 'featured_listings')->dropDownList([1=>'Yes',0=>'No']; ?>
@PaheerathanSelvarasa the readonly attribute don't works on a select element. It's a HTML problem.
To solve problems like this, I use one of the following approach on my projects:
@berosoboy Thanks, it was helpful!
Most helpful comment
first options are for the ActiveField class. Do it this way: