Thursday, January 29, 2009

Re: Validation of a disabled input field

In my experience a disabled field will not follow the rest of the
values to the server.
According the the w3c a disabled field "cannot be successful" which I
read as "can not have a value when submitted".

You can use the attribute "readonly" (only for text inputs) which
disables editing but the value will still be submitted. Or you have to
create a hidden field to "replace" your disabled one using javascript.

Look at how Cake uses hidden fields in forms to get some ideas.

/Martin


On Jan 29, 11:28 am, tobi_one <tobias.h...@gmail.com> wrote:
> Hi,
>
> is there a way to activate the validation of a disabled input field?
>
> In my view I have a field like this:
>
> <?php echo $form->input('templatefile', array('label' => 'Template',
> 'disabled'=>TRUE)); ?>
>
> The input field is disabled for the user but gets written to via
> Javascript. I would like to apply the "notEmpty" rule to this field,
> so that there is an error shown, if the form is submitted and the
> field is empty.
>
> Only problem: disabled=>TRUE automatically stops validation as well.
>
> Cheers,
> tobi_one
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: