Hidden required select field with default value
Hello, I'm trying to modify a form where I'm hiding a select field. This field is usually required. When setting the #type = hidden The field is hidden, but when trying to submit the form I get an error about the fields being required. Looking at the $form dump, I see that the select field has a default value. (a term id). I tried changing the Required to false when hiding but then the field looses its value. Is there some other property I need to set? Thanks Idan
I think you have to make your own validation function instead of using the one that comes by default and supports #required. Use #access (not #hidden) to hide the field. Then in your validator, check to see whether it's OK that the field is not filled in, and notify as needed. -Randy On Fri, Nov 11, 2011 at 8:50 AM, Idan Arbel <idan@arbel-designs.com> wrote:
When setting the #type = hidden****
The field is hidden, but when trying to submit the form I get an error about the fields being required.****
Looking at the $form dump, I see that the select field has a default value. (a term id). ****
I tried changing the Required to false when hiding but then the field looses its value.****
-- Randy Fay Drupal Module and Site Development randy@randyfay.com +1 970.462.7450
thanks but I’m not sure #access is what I need: this is and edit form, a long form with multiple field groups. If the user access the site in with profile/2/edit/company I’d like to hide all field groups instead of those in the company field group, but have them keep their pre-entered values. Doesn’t access deny access to the field? I don’t mind changing the required to FALSE since I’m hiding the field anyway… Idan From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Randy Fay Sent: Friday, November 11, 2011 5:55 PM To: development@drupal.org Subject: Re: [development] Hidden required select field with default value I think you have to make your own validation function instead of using the one that comes by default and supports #required. Use #access (not #hidden) to hide the field. Then in your validator, check to see whether it's OK that the field is not filled in, and notify as needed. -Randy On Fri, Nov 11, 2011 at 8:50 AM, Idan Arbel <idan@arbel-designs.com> wrote: When setting the #type = hidden The field is hidden, but when trying to submit the form I get an error about the fields being required. Looking at the $form dump, I see that the select field has a default value. (a term id). I tried changing the Required to false when hiding but then the field looses its value. -- Randy Fay Drupal Module and Site Development randy@randyfay.com +1 970.462.7450
On Friday 11 November 2011, Idan Arbel wrote: Hide want you want with jquery, no messing with validators as the form elements are all still there, just not visible to the user.
thanks but I’m not sure #access is what I need:
this is and edit form, a long form with multiple field groups.
If the user access the site in with profile/2/edit/company
I’d like to hide all field groups instead of those in the company field group, but have them keep their pre-entered values.
Doesn’t access deny access to the field?
I don’t mind changing the required to FALSE since I’m hiding the field anyway…
Idan
From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Randy Fay Sent: Friday, November 11, 2011 5:55 PM To: development@drupal.org Subject: Re: [development] Hidden required select field with default value
I think you have to make your own validation function instead of using the one that comes by default and supports #required.
Use #access (not #hidden) to hide the field.
Then in your validator, check to see whether it's OK that the field is not filled in, and notify as needed.
-Randy
On Fri, Nov 11, 2011 at 8:50 AM, Idan Arbel <idan@arbel-designs.com> wrote:
When setting the #type = hidden
The field is hidden, but when trying to submit the form I get an error about the fields being required.
Looking at the $form dump, I see that the select field has a default value. (a term id).
I tried changing the Required to false when hiding but then the field looses its value.
-- ----------------- Bob Hutchinson Midwales dot com -----------------
yeh i actually added a hidden class but i thought it would be better to use the form alter. On Nov 11, 2011 8:29 PM, "Steve Ringwood" <nevets@tds.net> wrote:
For that matter you can hide the field with css
Hide want you want with jquery, no messing with validators as the form
elements are all still there, just not visible to the user.
Try taking the value from #default_value and putting it in #value. Sent from my iPhone On Nov 11, 2011, at 7:50 AM, "Idan Arbel" <idan@arbel-designs.com> wrote:
Hello,
I’m trying to modify a form where I’m hiding a select field.
This field is usually required.
When setting the #type = hidden The field is hidden, but when trying to submit the form I get an error about the fields being required. Looking at the $form dump, I see that the select field has a default value. (a term id). I tried changing the Required to false when hiding but then the field looses its value.
Is there some other property I need to set?
Thanks
Idan
participants (5)
-
Bob Hutchinson -
David Metzler -
Idan Arbel -
Randy Fay -
Steve Ringwood