ajkosh
(Ajaykaushiksharma087)
September 7, 2014, 6:24am
1
hi i m saving form into db wat when i m again updating same records i want to keep some fields readonly so user cant change them ,i know how to handle from _form but how to handle from model or controller part
or easy way to handle in _form
i m justing checking before any field with if condition is it new record or not
how to do this yii2 in models rules section
array(‘date’, ‘readOnly’=>true, ‘on’=>‘update’),
seyyed
(Arash)
September 7, 2014, 8:10am
2
ajkosh:
hi i m saving form into db wat when i m again updating same records i want to keep some fields readonly so user cant change them ,i know how to handle from _form but how to handle from model or controller part
or easy way to handle in _form
i m justing checking before any field with if condition is it new record or not
how to do this yii2 in models rules section
array(‘date’, ‘readOnly’=>true, ‘on’=>‘update’),
I’m not sure but I think if can remove all rules for that attribute from rules and it’s doesn’t update.
also you can save value in temp variable in proper event, and write your own rule to reset attribute value.
ajkosh
(Ajaykaushiksharma087)
September 7, 2014, 9:53am
3
I’m not sure but I think if can remove all rules for that attribute from rules and it’s doesn’t update.
also you can save value in temp variable in proper event, and write your own rule to reset attribute value.
is there any way to make field readonly in update like in yii 1 was some thing like
<?php
echo $form->textField(
$model,
'email',
array('readonly'=>($model->scenario == 'update')? true : false)
);
?>
ajkosh
(Ajaykaushiksharma087)
September 7, 2014, 11:03am
5
it will make (tetxfiled) readonly when form is creating ,i want readonly when user try to update field .
when user inserting record first time then it should not be readonly ,but when record saved then user try to update then field should be readonly
ajkosh
(Ajaykaushiksharma087)
September 7, 2014, 11:16am
6
i got solution
so just check inside textinput field ,is it newrecord
below is my code
<?= $form->field($model, ‘name’)->textInput([‘readonly’ => !$model->isNewRecord]) ?>
but when i inspect element, and i deleted readonly.
i still can edit the value
omeraslam
(Buttflattery)
August 27, 2020, 2:40pm
9
this is wrong and wll turn the input readonly on the create and update both