Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am working on some conditional drop down forms and am encountering the following error:
I made a selection required in field A which will then trigger field B to appear (which itself then turns into a required field. I am using radio buttons and the value condition.
In both cases the "required field" type is indicated in the form it is however not enforced.
Comments
Comment #1
Aron NovakI can confirm that this is the case.
Some more info in my case:
If i choose "Insert value from widget", it fails to enforce the required-ness, if i choose "Set of values / any of these values", it works perfectly.
Comment #2
justindodge CreditAttribution: justindodge commentedAlso an issue for me, in my case a text field is dependent on any two of four available values in a select list. Unlike #1, the required field is still not enforced on submit even using "any of these values" vs the widget.
AWESOME module by the way!!
Comment #3
peterpoe CreditAttribution: peterpoe commentedI found this bug while fixing #1288522: Compatibility with profile2 (and others?) and sneakily fixed it in the same commit. ;)
Comment #5
iNade CreditAttribution: iNade commentedIt seems the bug is still happening when I'm using conditional fields with an image or video field.
However, I haven't tested it with other type of fields.
Comment #6
peterpoe CreditAttribution: peterpoe commented#5: For me required Image and Video fields work fine. Could you provide some more context please? (Content type fields setup, dependencies setup).
Comment #7
IshanComBr CreditAttribution: IshanComBr commentedi've been struggled with this for a while
the field itself needs to be checked as required also, not only in the manage dependency condition
Comment #8
peterpoe CreditAttribution: peterpoe commented#5: IshanComBr is right, check you have to check the "Required" checkbox in the field edit page.
Comment #9
perisdr CreditAttribution: perisdr commentedI am having the same issue. The scenario is simple. The values from a select list control if a text field becomes required or not. The fields are profile 2 fields.
I have patched the module but with no luck.
If I go to the manage page and set the field as required then when I hit submit even when dependency is not triggered I get an error that the field is required. If the dependency is triggered the fied gets two astersiks.
I do not set the field as required then even when the dependency is triggered, I can submit the form without inputting any value to the text field.
Seems there are many duplicate issues for this one:
#1412538: Dependee required when dependent checked rule is not enforced on profile
#1372284: Required field indicated but not enforced
#1227692: Required fields still required even when they are hidden
Whats even weirder is that some people say they successfully fixed where others failed.
Comment #10
retiredpro CreditAttribution: retiredpro commentedI found a tip from another thread that says patch #18 may fix the issue.
http://drupal.org/node/1562760#comment-6287750
With this patch I am able to get required fields to enforce. Here is my setup:
Comment #11
creact CreditAttribution: creact commentedIs this solution confirmed yet?
Comment #12
prjcarr CreditAttribution: prjcarr commentedIs there any update on this?
Current setup: Textfield (required) dependent on Radio buttons (yes/no). Textfield is "visible" when radio button has value "yes". The visibility works, however the text field is still being required even though it is not visible.
Using latest dev.
Comment #13
arosboro CreditAttribution: arosboro commentedThis patch no longer applies to the current dev. I feel like code needs to go in conditional_fields_dependent_validate() to enable this validation. I spent a few hours and created a patch in #1561272: Conditionally required fields are not required #8
Comment #14
prjcarr CreditAttribution: prjcarr commentedI tried the patch referred to in #13 against the latest dev but it doesnt fix the validation issue posted in #12. I also tried adding another dependancy that forces an optional field to be required but experienced the same problem (no validation).
Comment #15
arosboro CreditAttribution: arosboro commentedPatch in 13 is using fields that are not required. They are made required by conditional field's validation handler when the form is submitted.
Comment #16
prjcarr CreditAttribution: prjcarr commentedThanks arosboro, but still not working for me. I have an optional text field dependant on a yes/no radio button. When "yes" is clicked the dependancy makes the text field "required". The text field then indicates that it is required, but the form submits with it empty. Is this working for anyone else who has applied #13?
Comment #17
hass CreditAttribution: hass commentedSame issue with selectboxes of core widget type Select list that become required after a checkbox has been checked.
Comment #18
Nikdilis CreditAttribution: Nikdilis commentedThis is not a normal but a critical bug as many people (myself included) are considering the enforced fields as absolutely necessary - otherwise, this module is almost useless.
This could be such a nice and useful module, but the way it is right now, it's really (sorry for that) just a pain in the ass.
Another problem is that fields are required even if they are hidden:
http://drupal.org/node/1227692
What's the problem concerning this matter? Is it the states-api of Drupal or what? These issues are over a year old and still not fixed!!!
Maintenance status: Actively maintained ????
Development status: Under active development ?????
Comment #19
Sk8erPeter CreditAttribution: Sk8erPeter commentedI agree that this is a really critical issue, and should be fixed ASAP.
Comment #20
usmccampbell CreditAttribution: usmccampbell commentedI am also having a similar issue. I am making a date field required dependent upon a dropdown of status'. If the status is anything but "No Service", it is supposed to be required. However, it is allowing me to save the node, even if the status is any of the others. If I put "visible" or "invisible" in, it works just fine.
Comment #21
greg2010 CreditAttribution: greg2010 commentedSame bug is cropping up when I try to use required conditional fields with the entityforms module. Visibility works but Required does not (it allows submission of the form without the required field being filled in).
i.e.
Dependent: First name (text field)
Dependee: Add a contact (field_add_new_visitor) (checkbox)
First name is required when Add a contact is checked.
- Marks as required but allows submission of form without any data in the first name text field
AND
Dependent: First name (text field)
Dependee: Add a contact (field_add_new_visitor) (checkbox)
First name is required when Add a contact is checked.
- Works. Hides or Displays the first name field dependent on the Add a contact check box.
I tried only using one dependency at a time to see if they were in conflict but the same behavior occurred.
Comment #22
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedSame bug for me !
In the mean time I have created a custom validation rule for my entityform that does the job.
Comment #23
usmccampbell CreditAttribution: usmccampbell commentedWhat did you use for the for the "Custom Validation" rules?
Comment #24
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedI believe this comes from Entityforms itself... there is a "Validation Rules" tab admin/structure/entityform_types/validation_rules
If not, maybe field validation or just Rules itself.
Comment #25
_ib CreditAttribution: _ib commentedThe bug is still happening with 7.x-3.x-dev on account registration forms. It enforces Visibility but not Required state on text fields (one is a select list, one is an autocomplete form).
Comment #26
usmccampbell CreditAttribution: usmccampbell commentedI want to bump this. Still no solid solution on why date fields are not being upheld to the conditions set forth?
Comment #27
ThePickwickProject CreditAttribution: ThePickwickProject commentedI can confirm that this issue is currently still present.
If checkbox field A is checked, enable textfield B and make it required. A nice red asterisk appears, but the mandatory requirement for B is not enforced (you can leave field B empty, despite the fact that it is required).
Comment #28
rooby CreditAttribution: rooby commentedIt seems based on date that the commit mentioned in #3 is http://drupalcode.org/project/conditional_fields.git/commit/d81c084, however that does not address this issue.
From a quick browse over the code it doesn't seem like this could ever have worked as there is no logic anywhere for this case.
The only logic I see is in the js file, where it adds the required flag to the field in the UI.
There is no validation logic in the PHP code.
Because the field conditions are not ajax based and the field element array is already attached the only way I can see this working is if the js can modify the element value in some way that the PHP $form or $form_state can tell, so that there can be a validation hook that checks for this case and then checks that the field is not empty if it has been made required.
I have not yet looked into if/how this can be done but I will try to make some time.
Comment #29
rooby CreditAttribution: rooby commentedSilly me, today I realise that you can igone my previous comment.
There is validation php code and you can easily check the value of the dependent & dependee fields to determine whether it should be required or not.
I shall see if I can debug the issue in the next few days.
Comment #30
koppie CreditAttribution: koppie commentedI'd like to mark this as a duplicate of #1561272: Conditionally required fields are not required, even though the discussion here is newer, because the other issue has a patch already. I think the very fact that there were multiple open tickets for the same issue is what led to fragmentation in the first place. However, please feel free to reopen this one if necessary. I don't mean to step on anyone's toes.
Comment #31
rooby CreditAttribution: rooby commentedFrom a quick glance at that patch it seems like it is doing what we want.
I'll review that patch when I get a chance.
Thanks for the link.