i need to disable my field but i want to store its default value.
i stored default value in it and made it disable but when i create a record it showing error ‘field is required’ and when i remove its validation it stores 0 all time.
thanx in advance…
tomvdp
(Tomvdp)
January 29, 2015, 2:08pm
2
If you are talking about form fields: a disabled field is not sent with the POST data (if I remember correctly).
Possible fixes, any of:
-Make it hidden or read only.
-Add a ‘default’ rule to the model for that attribute.
-Initialise the value in init()
alirz23
(Alirz23)
January 29, 2015, 3:06pm
3
the easiest way I can think of just use a hidden field and set a default value like so
<?php echo $form->hiddenField($model, 'fieldName', array('value'=>'abcd')); ?>
otherwise look at the following thread
http://www.yiiframework.com/forum/index.php/topic/11960-preferred-way-to-set-dynamic-default-values-in-a-cactiverecord-model/
thank you all of you…
i used readonly instead of disable, now its working…