Behaviour of required conditional fields
jim0203 - May 4, 2009 - 14:40
| Project: | Conditional Fields |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | fixed |
Description
A few of the node types on my site have a controlling field ( a tickbox) which must be filled in. If the user ticks it, then a controlled field appears. This is a text field and also must be filled in.
Ideally, if the tickbox isn't ticked then I don't want an error message to be displayed due to the controlled field being left blank. This is what happens in two of the four occasions where this sort of setup is implemented on my node types. However, on the other two occasions Drupal complains that I haven't completed the controlled fields, even if they aren't visible.
Am I missing some setting, or is this a bug?

#1
Could you please export your content type and fields definitions and send them so that I can test?
(We have import/export compatibility now! You have to update to the latest cvs to make import/export work)
#2
Yes:
http://drupalbin.com/9266
The four controlled fields are each called "Please specify". They are controlled by on/off tick boxes: if the box is checked, the field is shown.
Two of the tick boxes are called "other"; the other two start with the word "special". It's the fields that are controlled by fields called "Other" that are always being required, even if they are not visible. Interestingly, these fields are contained with field groups. The other fields, which work as I'd expected, are not contained within field groups.
#3
What happens to me is:
#4
There was a wrong variable name on line 609. Patch provided. Also, committed to cvs since it is an easy fix. Thanks!
#5
Ask for reopening the issue, after applying the patch I have this problem: I got some required fields inside a controlled group and they give error even if they are hidden.
#6
@matteogreco: could you please export the content definitions and add to drupalbin.org so that I can more easily test? Thanks.
#7
Hi peterpoe, thanks for the "live" support; here is my content type: http://drupalbin.com/9272, the controlling field is field_tipo_art_pn, it controls the group group_det_banc, the required fields are field_conto_corrente and field_num_assegno.
PS: I'm not matteogreco, but matteogeco, from the name of the company I work for. ;-)
#8
Well done, kid! it seems to me that last dev version solves the problem, for me this issue could be closed.
#9
Ok matteog(
r)eco, I'll mark this as fixed. ;)#10
Automatically closed -- issue fixed for 2 weeks with no activity.
#11
Hello,
I have just applied the latest dev version and i am having the same problem here for the required field inside a controlled field group.
I have required fields, FieldA, that is not controlled by anything outside of the field group, FieldGroupA, (well it is supposed to be this way i believe),
That FieldGroupA is controlled by a conditional text select field, ControlFieldA.
When I select any options from ControlFieldA that does not trigger FieldGroupA, it gives me error that FieldA is required but it is invisible due to FieldGroupA is not triggered.
Do you have a fix for this?
Thank you,
Leon
#12
Hello again,
I found a work around is to set a default value for that required field...
But maybe yo have a better way to solve it?
Thank you,
Leon
#13
@peterpoe: I installed the dev version, and i do not get an error when conditionally hidden fields are required. However, if the required field is a select list, the field values are not unset - they're still saved in the node object.
#14
I am using the latest dev version and this is still not working. Required fields are still causing errors of left blank. I have a simple checkbox that as controlling a field group that contains required text fields.
#15
I have just committed a patch that fixes the issues with required fields reported by @leon85321 and @servantleader. There is still one issue remaining: required controlled fields inside a controlled fieldgroup still give the required error if they are left empty, triggered and the fieldgroup is not.
#16
I still have the issue here.
Using the last dev version.
The controlled fields are file_field, some option doesn't trigger any fiel_field but then the node isn't submitted because of these required fields. You can see in the content-type export here :
http://koumbit.pastebin.com/d12278597
#17
It would appear that conditional fields won't work with some required CCK fields, such as filefield or imagefield.
After some enquiry, I found that the filefield module's hook_validate() implements its own way of checking for the #required property: it appears to be checking against the CCK field's required setting returned by the content_types() function. Because of this, it ignores the work done by the conditional fields module using hook_form_alter() and empty required fields will always fail validation, no matter what conditional field does to the form.
#18
Still not working... but it would be great. What do you think? Is there any chance to fix it in the immediate future?
#19
Yes, I experimented with weight of modules but still experienced the issues mentioned above.
It would be great to be able to have this working with imagefield
#20
Did the patch in #4 get reverted? Or is there now another typo which looks identical on line 654?
#21
#20: could you give more context? Patch in #4 has not been reverted.
#22
#18 Fixed in dev!
#23
Sorry. I misread the code. There is no type. :) I was looking at the wrong place.
#24
Ok cdale, this is good because I hate those required fields - when I have to fill them in the first place ;)
So I mark this as fixed, feel free to reopen if the required fields require some more attention.