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.


Aron Novak’s picture

I 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.

justindodge’s picture

Also 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!!

peterpoe’s picture

Status: Active » Fixed

I found this bug while fixing #1288522: Compatibility with profile2 (and others?) and sneakily fixed it in the same commit. ;)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

iNade’s picture

Status: Closed (fixed) » Active

It 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.

peterpoe’s picture

#5: For me required Image and Video fields work fine. Could you provide some more context please? (Content type fields setup, dependencies setup).

IshanComBr’s picture

i'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

peterpoe’s picture

#5: IshanComBr is right, check you have to check the "Required" checkbox in the field edit page.

perisdr’s picture

I 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.

retiredpro’s picture

I found a tip from another thread that says patch #18 may fix the issue.

With this patch I am able to get required fields to enforce. Here is my setup:

  • dependent field set as required
  • the dependent field is 'visible' when the dependee 'has value'
  • condition 'value'. values input mode 'insert value from widget...'. and choose the radio option that I wanted
creact’s picture

Is this solution confirmed yet?

prjcarr’s picture

Is 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.

arosboro’s picture

This 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

prjcarr’s picture

I 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).

arosboro’s picture

Patch in 13 is using fields that are not required. They are made required by conditional field's validation handler when the form is submitted.

prjcarr’s picture

Thanks 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?

hass’s picture

Same issue with selectboxes of core widget type Select list that become required after a checkbox has been checked.

Nikdilis’s picture

Priority: Normal » Critical

This 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:

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 ?????

Sk8erPeter’s picture

I agree that this is a really critical issue, and should be fixed ASAP.

usmccampbell’s picture

I 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.

Dependent - Date Started (date pop-up)
Dependee - Status (Select List)

Condition: Value

Values Input Mode: None of these values (NOT)...

Set Of Values:
No Service

Interaction with Other Dependencies:

Form State: 

Edit Context Settings:
Hide the dependent if the dependee is not in the form (is checked)

View context settings:
Hide the dependent if the dependency is not triggered
Hide the dependent if the dependee is not viewable by the user
greg2010’s picture

Same 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).

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


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.

Nicolas Bouteille’s picture

Same bug for me !
In the mean time I have created a custom validation rule for my entityform that does the job.

usmccampbell’s picture

What did you use for the for the "Custom Validation" rules?

Nicolas Bouteille’s picture

I 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.

_ib’s picture

The 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).

usmccampbell’s picture

I want to bump this. Still no solid solution on why date fields are not being upheld to the conditions set forth?

ThePickwickProject’s picture

I 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).

rooby’s picture

Component: Compatibility w/ other modules » Code

It 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.

rooby’s picture

Silly 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.

koppie’s picture

Status: Active » Closed (duplicate)

I'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.

rooby’s picture

From 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.