I have some required fields that are only made visible when a selection is made from another unrequired select box. There was some quirky behavior in regards to the required fields, namely that when no selection was made on the top level check box, fields were still being validated as being required.

I find the code in this module incredibly hard to follow and it screws with your mind trying to debug it!

Attached patch resolves the problems that I was having, though I honestly don't know if this is the right way to go about it.

Comments

Status:Active» Needs review
StatusFileSize
new1.14 KB

Status:Needs review» Fixed

Today's commit: Remove entity view handlers in favor of a more generic solution should have solved this problem as well. Please test and feel free to reopen if this is not the case.

Status:Fixed» Needs work

Tested with latest dev: it does work a little better but not quite there:

- if a field A was required and hidden by an other field B, the field isn't required anymore (correct behaviour)
- but if the action is undone by setting field B back to the original value, field A is not set back to required (although the red * does re-appear)

I believe this is solved when #262453: Grouping dependencies by dependent with OR/XOR evaluation is solved because then you can add one row to toggle hide/show and another to toggle required?

There is still a related issue to this in regards to radio buttons.

When you make a required radio button not required, it passess the required validation.
However, a non-required radio button should have a N/A value, which it doesn't because it has just had its required flag removed and nothing else (See also #1299818: When making radio buttons required using a condition the N/A option is still available).
Because of this you then get an "An illegal choice has been detected. Please contact the site administrator." error, because of #811542: Regression: Required radios throw illegal choice error when none selected.

The problem described in #5 only exists if you make the radio required but do not set a default value.
You can work around it by giving it a default value (not ideal in some cases).

I had this problem too and got around it using rules->form events. Here are the steps I used:

Form events has 4 steps and it's explained in the Advanced Help.

1. On rules ->form events, select Enable event activation messages on forms
2. On the form you want to enable the form rules for, click enable first and then a box appears and select activate
3. On rules ->form events, select Display form element IDs
4. Go back to your form and the element IDs you need to create the rule are there.

Then add a rule as usual. The process also added options for what you can do with that particular form.

After you've done all this you can uncheck those two boxes on rules-> form events page.

For the triggered rule itself, this is what I did:

A. On event: select the form you want and select the action. I selected 'form is being validated'.
B. Condition 1: form element has value: the control field details. For example, I have a radio field with yes or no: field_a[value] yes
C. Condition 2: form element has value: the field that is required field_b. I validated it to ensure it was not empty with this snippet and selected the box Negate.
return array( 0 => array('value' => NULL));
D. Do: Set a form error.

This will check that the required field is not left empty. Which is the same thing as making it 'Required' in my instance. I left the conditional field stuff intact so that the second field can appear. You will need to have the second field in the content-type not set to required.

I hope this helps someone!

There are still some field types that is required, but not visible throws error. This is such and old issue, why is this so hard to fix?

Having the same issue. I am hiding some textfields with a checkbox. My condition is: if checked => !required (optional).
Drupal is giving me an error, that the hidden fields are still required after submitting...

Would really appreciate this being fixed. =)

I have a hidden field that is required. Is there a patch that would make it only required if it is visible?

Status:Needs work» Fixed

#5: This is a Drupal core problem, and will not be addressed by Conditional Fields
#8: Which field types?
#9: Use the condition "value", not "checked" or "unchecked", since whit the latter the condition is not actually evaluated when the form is submitted (this is by design to avoid duplication of functionality. But "checked" or "unchecked" are causing a lot of confusion in users and will be probably removed).
#10: More context please?

#8 and #10, if you have problems with required fields, please open a new issue and specify the exact steps to reproduce them, thanks.

Status:Needs work» Fixed
StatusFileSize
new47.06 KB
new4.02 KB
new2.37 KB
new4.18 KB

@PeterPoe:
Regarding to #8 and #9 (I think) here is an example:
The fields field_kontoinhaber, field_kontonummer, field_kreditinstitut, field_bankleitzahl are still required even though the option "Paypal" has been selected => See errors.
and vice versa...
Maybe my settings are not correct - if so, please advice.
See attached images. (In the settings.png 'erforderlich' means required and 'sichtbar' means visible)

Status:Fixed» Needs work

Status:Fixed» Needs work

For me the hidden required fields work fine when I use them in the registry but then there is a problem when the user try to edit its profile. The hidden required fields are mandatory so the user have to unveil them, fill them with something to be able to save the profile. What can I do? Is there anything I can change in the settings to avoid this issue?

subscribe - any idea when this will be working?

Priority:Normal» Major

I think this is major because if I submit a form where a hidden field fails validation there is no indication to the user that there has been a validation issue and the form still submits, however some other strange things can happen, for example if you are using the field collection module the field collections will silently fail to insert their values to the database.

I know that is partly a field collection issue (see #1549364: Data not being saved on initial creation), however it is also a problem with silent field validation errors that should not be happening.

Also, the only real work around is to create a non-required field and set it to conditionally be set to required at the same time it is set to visible, but that is not viable due to #1372284: Required field indicated but not enforced, so there isn't really a workaround for this issue currently.

I am really struggling with this module - I've read the warning about not using it on production sites, but I don't want to downgrade & rewrite new site to D6 to get dependent fields to work.

The module seems to work fine on my dev site, but the same behaviour cannot be replicated on production site. I've used bundles to import field settings, ctools export to import field validation rules. This all works fine, but I just cannot get past point of hidden fields preventing the form being submitted (hidden fields should only be required if they are visible). I have tried re-creating them many times, tried to get them in the same order (which is a bit random), and reset caches etc. The module code is too complicated for me to even begin to start looking at.

Can anyone offer any help or advice?

UPDATE - it seems I was a bit too hasty in blaming this module. I'm also using Rules Forms Support to provide a custom rule - deactivating the form, and then re-activating it seems to have cured the problem.

I am posting here because I see a lot of the other related issues were closed as duplicate. My issue boils down to required dependee throwing validation error when hidden due to unchecked dependent field.

FYI, I am on alpha-1.

I have Rules Form Support installed, but it is not configured on the content type in question.
I have Field Permissions disabled for the required field.
The dependee field is a simple text box.
The dependent field is a checkbox.

The only error is the validation error that the hidden text field dependee is empty.

Does anyone have some advice as to the correct way to configure the dependee to be required and not throw validation error when hidden? What additional information would be helpful?