When the dependent is set up to be required when the dependee is triggered, then the JS is added correctly the user will see the red star, but when saving the node the module does not check if the field that is required is filled or not.

However it would be nice if drupal enforced this required state.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nagy.balint’s picture

Status: Active » Needs review
FileSize
1.33 KB

I created a patch that adds this functionality in the element's validate hook.

It most likely can be improved but this version works for me now.

cdracars’s picture

Tested patch and seems to work fine.

jacktiong92’s picture

Hi guys! I've installed Conditional Fields 7.x-3.0-alpha1 module and I need some help here. I am using Node Registration module and I've setup a form through node registration module and merge it together with the conditional fields module. In my form, the registrant is required to check certain checkboxes and extra fields (that needs validation) will appeared. However, I am facing the same problem as nagy.balint because even if the registrant submits the form without filling the necessary fields after the checkbox has been checked, the form will still be submitted. I have also tried to applied this patch but it is still not working. Please help me sir! Thanks in advance!

Outi’s picture

Hi, I've tried this patch, too, and it's not working for me.

I have a simple text field (TF1) with another text field as dependent (TF2). When the TF1 is empty, the TF2 is hidden. When the TF1 is filled, the TF2 is showed and required. There is the little star next to it but I can anyway save the form without filling the TF2.

Do you nagy.balint or does someone else have any idea of what could be wrong ?

Outi’s picture

Actually the patch seems to work when the debendee is set to have a value. In my case that's ok! With other conditions it doesn't seem to work.

System Lord’s picture

This patch seems to be working. Thank you!

elpino’s picture

This patch worked for condition 'when dependee has value...'.

Other conditions would have to be tested or implemented.

Croga’s picture

No luck. I'm using "when dependee has value..." and the patch did not solve the problem.

System Lord’s picture

Receive this list of notices when setting up new fields and dependencies. They're lines from this patch.

•Notice: Undefined index: #entity_type in conditional_fields_dependent_validate() (line 675 of /home/site/public_html/sites/all/modules/conditional_fields/conditional_fields.module).
•Notice: Undefined index: #bundle in conditional_fields_dependent_validate() (line 675 of /home/site/public_html/sites/all/modules/conditional_fields/conditional_fields.module).
•Notice: Undefined index: dependents in conditional_fields_dependent_validate() (line 676 of /home/site/public_html/sites/all/modules/conditional_fields/conditional_fields.module).
•Warning: Invalid argument supplied for foreach() in conditional_fields_dependent_validate() (line 677 of /home/site/public_html/sites/all/modules/conditional_fields/conditional_fields.module).

The dependency is: "visible" when x is selected. Not setting "Required" at all. The only thing I've done different than usual is I'm using this on term reference field with the "Autocomplete term widget (tagging)" widget (as the Dependent). Maybe that has something to do with the errors? The dependee is the usual term reference - select list.

Update: switched from "autocomplete" to "select list" and still same notices/warning. I'm using CF a lot on my site and don't see any errors with them. Could my vocabulary be corrupt?

Update: created new vocabulary. Still same notices/warning. So, I have two fields/vocabularies. One with all 50 states names/terms (dependee) and the other with all Ohio city names/terms (dependent). When I select any state other than Ohio (dependent hidden) then "save" I get no errors. Only when I select Ohio and save do I get these errors.

Update: Installed 7.30 and these errors don't appear. However, not having this patch takes me back to the topic of the thread.

NWOM’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#1561272: Conditionally required fields are not required