When activating a dependency that changes the required state of a field, required fields are not respected and the entity can be saved without values.

#74 conditional_fields-required_empty_filled-1561272-74.patch7.13 KB_KurT_
PASSED: [[SimpleTest]]: [MySQL] 160 pass(es).
[ View ]
#63 conditional_fields-required_field_validation-1561272-63.patch4.4 KBvflirt
#52 conditional_fields-required_field_validation-1561272-52.patch4.45 KBvflirt
#41 conditional_fields-required_field_validation-1561272-41.patch4.18 KBfreblasty
FAILED: [[SimpleTest]]: [MySQL] 141 pass(es), 19 fail(s), and 0 exception(s).
[ View ]
#38 conditional_fields-required_field_validation-1561272-38.patch3.12 KBkunago
FAILED: [[SimpleTest]]: [MySQL] 108 pass(es), 52 fail(s), and 0 exception(s).
[ View ]
#32 conditional_fields-required_field_validation-1561272-31.patch3.07 KBvflirt
FAILED: [[SimpleTest]]: [MySQL] 108 pass(es), 52 fail(s), and 0 exception(s).
[ View ]
#18 conditional_fields-required_field_validation-1561272-18.patch2.87 KBarosboro
FAILED: [[SimpleTest]]: [MySQL] 108 pass(es), 52 fail(s), and 0 exception(s).
[ View ]
#8 conditional_fields-required_field_validation-1561272-8.patch2.79 KBarosboro
FAILED: [[SimpleTest]]: [MySQL] 108 pass(es), 52 fail(s), and 0 exception(s).
[ View ]
#3 scree1.PNG11.28 KBkaizerking
#3 scree2.PNG12.81 KBkaizerking
#3 screen3.PNG14.11 KBkaizerking
#3 scree4.PNG15.4 KBkaizerking


peterpoe’s picture

I cannot reproduce this. Can you detail the field and widget types used, and the dependency settings?

reych9’s picture

I am using two fields:
dependent: entity reference - select list (required)
dependent: text list - selection fields (required)

when I do dependence for the bound field be hidden, it is hidden, but when it is displayed can be saved without value.
I even another rule to make it required and shows two asterisks next to the field, but still require vacuum value and saved

kaizerking’s picture

new15.4 KB
new14.11 KB
new12.81 KB
new11.28 KB

I have same problem
I have 2 fields either of the filed is required,settings
Filed_1, and Field_2 or visible when field_a has value=1
field_1 is required if field_2 has value=0
filed_2 is required if field_1 has value=0
When is save without selecting either one the content is saved without triggering the dependency
Also an error message "field_1 or Field_2 is required " is required
please see attached png files, the operation is complete after screen4 but if i save at screen2 stage it allows to save

reych9’s picture

Priority:Normal» Major

any help??

reych9’s picture

Priority:Major» Critical

It's really important able to use this module in user entities types.

perisdr’s picture

I am also dealing with such a problem.

I have a select list and 3 text fields. All of them are visible. If you select any value in the select list the text fields become required.
But the user can hit save without inputting any values to the boxes.

The weird thing is that I would sworn that it was working a while ago. I am looking to see if any new modules may have caused this but so far no luck.

perisdr’s picture

Ok, I am using the 7.x-3.x-dev version that I believe was released on Tue, 13 Sep 2011 00:13:51 GMT
In that version when you go add a "required" dependecy there is nothing more than the configuration.

Now in the last version I see a lot things where added along whith this informative text:
The Javascript form state that is applied to the dependent field when the condition is met. Note: this has no effect on server-side logic and validation.

That means that the only thing that this does is add just the asterisk. Nothing else. Correct?
So you could say that this is working as designed. I am still curious though as I remember testing that feature before adding it. I will try to use my old version on a clean drupal installation and come back with the results.

EDIT: Still no luck
Some similar issues:
#1372284: Required field indicated but not enforced
#1412538: Dependee required when dependent checked rule is not enforced on profile

arosboro’s picture

Status:Active» Needs review
new2.79 KB
FAILED: [[SimpleTest]]: [MySQL] 108 pass(es), 52 fail(s), and 0 exception(s).
[ View ]

It wasn't fun, but I made a patch for this. It needs to be reviewed, because I'm not sure what side effects will be from changing:

// Check if this field's dependencies were triggered.
-  if (conditional_fields_evaluate_dependencies($dependent, $form, $form_state)) {
-    return;
$triggered = conditional_fields_evaluate_dependencies($dependent, $form, $form_state);

Any thoughts, comments are welcome :)

bharat83’s picture

Patch not working for me.

hass’s picture

I have several select boxes that depend on one checkbox. This means if the checkbox 'foo' is checked, 4 other select boxes are required. I see the required marker is shown next to the select boxes, but the requirement is not enforced on save. These select boxes have a value of _none, but the form is saved without setting them to any other value. Additional I have a checkbox in the same form that is required, when 'foo' checkbox is checked and a value of a select box is 'bar'. The selectboxes are all core widget type Select list.

None of this conditions work. I can always save without fulfilling the requirements. The module is totally useless. No idea why it's installed on 10K servers.

Sk8erPeter’s picture

@hass: I agree that required fields should not just be indicated, but rather enforced, see the other issue: #1372284: Required field indicated but not enforced, and I also agree that this is a very big problem, because this is one of the module's main tasks.
But instead of simply calling this module useless and cr@p, you could rather help the developer(s) find out the source of the problem, and write a useful patch to be able to mark this issue as resolved and help many site maintainers too.
By the way, this module is useful for other tasks too (e.g. simply toggling the visibility of some fields according to some conditions), its task is not just the one you need it for (enforcing required fields to be filled out). BUT you're right that this issue still remains critical.

koppie’s picture

Priority:Critical» Major

I've marked two other discussions as duplicates of this one:
#1372284: Required field indicated but not enforced
#1412538: Dependee required when dependent checked rule is not enforced on profile

I'm also changing the priority back to "major." The priority flag isn't meant to be used as a bump if your issue is being ignored. Please see https://drupal.org/node/45111. I agree that this issue definitely deserves major priority; it's an important function that does not work, and has received a lot of discussion and multiple patches. Clearly there are a lot of people who think this is important.

I'm going to review the patch in #8 when I have a chance.

koppie’s picture

Status:Needs review» Needs work

I'm afraid the patch doesn't work for me either.

koppie’s picture

I have a workaround. I added a custom module to my own site with the following code:

function first_node_validate($form, &$form_state){
    if ((strpos('incident', $form->type) !== false)) { // Check the content type
        if (($_REQUEST['field_incident_type']['und'][5]) // Check the dependee field
             && (!$_REQUEST['field_incident_security_action']['und'][0]['value'])){ // Check the dependent field
            form_set_error('field_incident_security_action','You must specify a <em>Security Action</em> on the Security tab.');
            $errors = drupal_get_messages();
            foreach ($errors as $type => $id) {
                foreach ($id as $message){
                    // Loop through individual messages, looking for ones to remove or replace
                    if (test_for_invalid_error($message)===FALSE){
                    } elseif (test_for_invalid_error($message)!==TRUE){
                        drupal_set_message(test_for_invalid_error($message), $type);

It checks for the specific content type, checks to see if the "dependee" field is set, then checks to see if the dependent field is empty. If it is, then it returns an error.

The problem is this is a "one off" solution that only works for a pre-defined content type with a pre-defined field. But I'm hoping someone can take this logic and apply it to a more general solution, and maybe even a patch!

seaneffel’s picture

Issue summary:View changes
Priority:Major» Critical
Status:Needs work» Active

Still busted. I looked at this module last year for a possible solution, but I see this specific problem is still unsolved.

Under no circumstance can I make the module respect the required status of the text fields. Tried setting the dependency on a widget value or on a regular expression. Tried with the target fields set as required or optional. Tried with the dependency state switching between option and required. Tried setting the dependency based on checkboxes and radio buttons. Tried setting dependencies on whether the field is empty or filled. Tried it all.

I can always save the node with no value in the conditionally required fields. The check against the required field state is jacked across the whole module.

If you want to reproduce this, set this up:

Dependee field:
List (text) field with values A and B

Dependent fields:
Text Field A
Text Field B

When List field reads A, make Text Field A required.
When List field reads B, make Text Field B required.

I'm advocating that this is a critical bug. I say it's critical because the feature says it can conditionally set the required state of a field and it just can't. There are no working patches for this, either.

seaneffel’s picture

Title:Required field is saved without content in user fields.» Conditionally required fields are not required

Oh, and a fancy new title that describes the broad impact of this bug.

hass’s picture

arosboro’s picture

new2.87 KB
FAILED: [[SimpleTest]]: [MySQL] 108 pass(es), 52 fail(s), and 0 exception(s).
[ View ]

I have found a bug with the form_set_error statement, that was causing validation to fail. I believe this patch will work in most cases.

seaneffel’s picture

You might have a great patch there, but it doesn't address this issue. Applied to 7.x-3.x-dev and the conditionally required fields are still not enforced as required. The little red asterisk still suggests the fields are switched to required, but they are not enforced.

arosboro’s picture

I'm applying this to the non dev branch, and it gives a form error when you try to checkout, maybe you could install devel and come back here with the value of the the $error_key variable and the name attribute of your required field. They should match for form_set_error to trigger.

seaneffel’s picture

@arosboro: I'm trying to get conditionally required fields to enforce their required status, but I can't test that on the current recommended release because conditional fields do not store values (this old thing: https://drupal.org/node/1542706).

The current dev release can store values. Can we get a patch against that one?

seaneffel’s picture

On a side note, my specific goal of setting fields as both required and visible based on the value of another field can be reached with this module: https://drupal.org/project/field-conditional-state

But it can't be reached with this rewrite of the same module because of unstable code (so far): https://drupal.org/project/field_conditional_state

Note the difference in underscores and dashes in the URL.

Not jumping ship on this issue, though. I prefer to use this module because of the higher usage among the Drupal community.

Ndesign’s picture

subscribing to issue

kbasarab’s picture

So looks to me like the patch in #18 gets us almost there. The issue is that the check for:

          if (empty($input_state)) {
            form_set_error($error_key, t('The !title field is required', array('!title' => $dependent['#title'])));

That $input_state variable is not just a string but an array with the structure $array[0]['value'] for a standard text field. This structure changes with fields such as a link field though and becomes $array[0]['url']. We probably need to add some logic to see what the field type is and return that. No error is reported because $input_state is not empty so it doesn't set the error. We need to be checking the value of that or whatever that final attribute is.

er.pushpinderrana’s picture

#18 patch not working as expected. Even after applying this patch it created another issue, now Conditional fields values not saving.

zmove’s picture

#18 doesn't fix the issue.

I'm a little afraid to see a critical issue that is 2 years old. It seems a so basic need to have a required field depending on another field and a module that have more than 30k download still can't do it correctly ?

Did I miss the solution ? Looked in the issue queue and it seems there a lot of issue related to that problem with no working solutions...

The Field Conditional State can be an option for some people, but not all the fields types are compatible with it (in my case, a vat number field, that's not compatible), so the only solution I have is a working conditional fields module.

rooby’s picture

re #26:
Field conditional state does not do required properly either (and I believe it is not something they are looking to add as it is not a part of the drupal core state system that is used).

The reason it hasn't been fixed yet is that it is not trivial to fix and it would seem no one has needed it enough to put the time into fixing it.

I would also argue that this issue shouldn't be marked critical as it is a known issue and doesn't actually break your site. It can lead to problem data though so I understand the concern.

seaneffel’s picture

I think critical is a good choice for a bug in a module called Conditional Fields where the fields that are required by condition are not actually required. It would seem that a central piece of the module's function isn't working right.

zmove’s picture

+1 to #28, It can be considered as critical when a field that should be required is not. Especially when it's one of the main task of a module.

Imagine you need to register professionnal user depending on a required field that doesn't work, it can completely alter the value of your database... definitely a critical problem.

vflirt’s picture


a bit better checking for empty fields going trough _field_filter_items() as in field_default_validate().
However with file/image fields the title cannot be taken when setting error but nonetheless there is error set so at least it is working :)

vflirt’s picture

Seeing 1 more problem with reference fields, should be better to use form_state['values'] instead of form_state['input'].

vflirt’s picture

new3.07 KB
FAILED: [[SimpleTest]]: [MySQL] 108 pass(es), 52 fail(s), and 0 exception(s).
[ View ]

Adding the patch.

chefnelone’s picture

#32 It allows the form to be saved. The message "The xxxx field is required" is shown once the form sent.

I added a Required dependency field to the commerce checkout (billing fields)
form at: http://localhost/example.com/en/checkout/28 [1]
But the form is saved even if the field is empty.

kunago’s picture

@vflirt: As I was able to discover running through the code, this patch works only for such conditions when the dependent is evaluated against a "value", not conditions such as "empty" etc. The "conditional_fields_dependent_validate" function does not seem to be entered otherwise.

vflirt’s picture

@kunago : I am not quite sure I understand what you mean. From what I see looking at function "conditional_fields_form_after_build" it will call "_conditional_fields_element_add_property($dependent_form_field, '#element_validate', 'conditional_fields_dependent_validate', 'append');" no matter the condition "value" or not so "conditional_fields_dependent_validate" will always be called. This patch is calling the proper "empty" function for the field the same way drupal core does it in order to check if it is empty or not. I have taken the patch from comment#18 and addded a couple of lines.

kunago’s picture

@vflirt: I made a few tests and whenever I wanted to make use of your patch, it did not pass through the "conditional_fields_dependent_validate" function unless you set the "value" to check for. I wanted to use "empty" and it did not work. Tried to output whatever message with devel module I placed in the function. If it works for you, it certainly does not work for me.

vflirt’s picture

as I described I added small thing to the patch so I cannot take any credit for the whole patch. I want to help you figure out your issue and make this patch even better but I cannot understand your issues. Could you try ti either describe how to setup the fields and conditions or export a feature so I can take a look and understand what is the problem? Also this way other people can also join in and help as this benefits all the community :)

Kind Regards,

kunago’s picture

new3.12 KB
FAILED: [[SimpleTest]]: [MySQL] 108 pass(es), 52 fail(s), and 0 exception(s).
[ View ]

I suggest one change in the patch. While it works for forcing a field to be required when it is set to be optional, it does not work the other way around, meaning force a field to be optional when it is set to be required.

The modification seems to fix it.

EDIT: This patch only works for my specific case. That leads me to a simple fact that the module does not have the logic very well thought out.

VVS’s picture

Kunago thanks for #38. Patch working, but I do not change value in my date field! Change, but after save node - value set to old. :(

kunago’s picture

@VVS: The module seems to handle well the situation, when a field is optional, set is as required. My use case was the opposite, meaning set a field that is required as optional. In the end I ended up using a very dirty hack in the module to force it behave the way I wanted but it definitely is not a solution.

freblasty’s picture

new4.18 KB
FAILED: [[SimpleTest]]: [MySQL] 141 pass(es), 19 fail(s), and 0 exception(s).
[ View ]

Attached patch is based upon the changes made in #38 and should fix the problem mentioned in #39.

freblasty’s picture

Status:Active» Needs review

The last submitted patch, 8: conditional_fields-required_field_validation-1561272-8.patch, failed testing.

The last submitted patch, 32: conditional_fields-required_field_validation-1561272-31.patch, failed testing.

The last submitted patch, 38: conditional_fields-required_field_validation-1561272-38.patch, failed testing.

The last submitted patch, 18: conditional_fields-required_field_validation-1561272-18.patch, failed testing.

Status:Needs review» Needs work

The last submitted patch, 41: conditional_fields-required_field_validation-1561272-41.patch, failed testing.

Nikdilis’s picture

zmove’s picture

#41 doesn't work. In fact, I don't see the difference with the original conditional fields.

I'm on my user registration form, I have a required dependency. When I check the checkbox that make the other field required, the required red mark appears (on each of the checkboxes instead of the checkboxes label (first bug)) and I can submit my form without filling the required field, it will pass.

So the patch seems to correct.... nothing...

Status:Needs work» Needs review

Status:Needs review» Needs work

The last submitted patch, 41: conditional_fields-required_field_validation-1561272-41.patch, failed testing.

vflirt’s picture

as I have mentioned before $dependent['#title'] is not always set in conditional_fields_dependent_validate which causes Notice:  Undefined index: #title. As form element structure is a bit inconsistent depending on field types is hard to actually figure out the field instance and field info does not have enough info to show proper title. I have added a small work around for such cases which covers only image field in my specific case but would be nice if more people look into it to figure out more general approach to it if needed to go further then $dependent[0].
One idea is to get the field info and then try to figure out the entity info to get the instance and get the title from the instance but considering the different amount of field types and how they handle multiple values that might be quite complicated combined with translations.
Other option could be to descend into element children of dependentrecursively and look for #title but that wold not be quite accurate.

Adding the small difference to patch from #41.

Svetozarrr’s picture

#52 is working for me, but dependent field doesn't highlight, if validation hasn't passed.

mohmmadalabed’s picture

I agree @Svetozarrr #52 is working but without highlight

lex0r’s picture

Patch #52 doesn't work for me. I still don't get any validation...

ilgriso’s picture

Patch #52 doesn't work for me. I still don't get any validation...
This thing is really making me crazy.
I tried the module in a clean installation of drupal (even via simplytest.me site).
If I create a field visible and required by another field: the process seems to work (the field is displayed with the red star), but if I don't insert any value in this field no alert message are shown and the data are correctly insert (without the required - conditional - fields).
Am I doing something wrong?

davewilly’s picture

Fantastic module, but this shortfall makes me a little sad. I guess for the moment a work around is to hook the form submission and manually validate any required fields.

koppie’s picture

Yup. That's exactly what we did.

shaisamuel’s picture

Patch #52 doesn't work for me. The Dependent field (Integer) is required (field setup), and saved even when its empty.
I also added an addition rule to make it require on the same Dependee condition and it does not work.

torekaas’s picture

this is my first post...hope to help someone!!
these are the configurations I made to set a field required based on another field value:
field_esito List (text) Select list ...single value not required (YES or NO)
field_data_esito Date Pop-up calendar .....REQUIRED
In Manage dependencies I set this:
Data esito (field_data_esito) Esito (field_esito) Data esito is visible when Esito has value "1".

If field_esito has value NO the content is saved without error.
After selecting the value YES on field_esito the field_data_esito is shown and must be fill with a date value in order to save the content.

I used conditional_fields 7.x-3.0-alpha1

knalstaaf’s picture

Confirming that #52 is not working for my (binary) dependee.

@torekaas: your approach looks similar to the conditional components used in Webform: if it's not shown, it's default requirement is disabled as well. I tried it myself and this seems to work in my case.

  1. I made the dependent field required by default.
  2. Then I made a conditional in which the (binary) dependee must have only one of these values (XOR): 0 in order for the required field to show / be visible.

0 is the "Off" value in my case, so the required field must only be visible when the dependee is unchecked. Mind the XOR-option in the Values input mode field, it won't work with the other options (and, or, not).

That's the only dependency rule that goes in there (no longer need for a "make required" dependency rule). Make sure to clear the cache if no change is visible at first sight.

I'm not sure if this approach serves the whole audience, but I guess some may benefit from it. The issue remains though.

kaizerking’s picture

For now this patch worked for me. I don't know the implications with this patch

vflirt’s picture

There is one small bit in the patch that is missed and cause some tests to fail. Adding that bit.
The patch seems to work quite well for all core fields and their conditions.

smurfxx’s picture

Patch #63 solved partially my needs:
I have a select field and I want to show and make required a text field if I select a certain value.

Without the patch I cannot save the text field value, now it saves but the field doesn't become required.

vflirt’s picture

I have exactly the same setup :
1 condition select field
1 select field that is not required but when e certain value from the select is selected then the text field becomes required.
Without the patch you can save the form with no issues but with the patch I am not able to save the form and I am shown error message. If you want I can upload screenshots or features with the setup. I have tested that with all core fields and it is working as expected: when a certain value is selected then the field becomes required and you cannot save the form.

smurfxx’s picture

I think that the difference between my setup and your is that for me even the select field is required.

I tried again to patch (I was not sure that I applied well) but I have the same results, the text field can be saved empty.

I applied the patch #62 to the latest dev version.

vflirt’s picture

I have tested with the select (condition) field required and not required and had no issues. I will upload some screenshots and a feature export file for my setup.

vflirt’s picture

Here is a link to the screenshots and exported feature:

smurfxx’s picture

Thank you very much, I'll try that soon!

EDIT: I don't understand one thing: do I have to apply all the patches to the latest dev version or just last patch? Or can you post a full module that works?

vflirt’s picture

I added copy of the module as well in the dropbox.
version = "7.x-3.0-alpha1+15-dev"
although in the folder the patch is from 52 you can see the code that it has 63 applied. The diff between the 2 patches is only 3 new lines.
No other patches has been applied to the module.

_KurT_’s picture

patch #63 doesn't work for me. Tested on conditions:
"Image is required when Tags is empty."
"Image is required when Tags is filled."
with standard drupal article fields.

smurfxx’s picture

First of all thank you very much for your support and kindness!

I uninstalled old module, deleted file, copied your module and enabled.

I have always the same result, but now I see the difference between my case and your case:
in your case you have a normal select list, in my case I have a checkbox select, I changed the rule from "Insert value from widget" to "All of these values (AND)" and putted the value manually. Now it works!!!!

For some reason if I use the value from widget the dependency desn't work. For me it's good now!

vflirt’s picture

Yep, it does not work for the case you have described for a reason that is core part of the conditional fields module :

Options that need to evaluate if the dependency is triggered only apply if the condition is "Value"

so unfortunately there is a lot more to be done when working with conditions other then "Value" like empty, filled and so on.
It seems that most people work with a select field for condition so using the "Value" condition is what is selected.

This is a 2 step process:
1) check that we have triggered dependencies for the field
2) check what should happen based on those triggered dependencies
this patch covers mostly the second part but is not covering the first one. It does work for it base issues:
when a dependency is triggered and field should be required then it is marked as required.
This patch is work in progress and I agree that fixing both steps is to be expected. If anyone is willing to put more time into adding cases for "empty" and "filled" then that would be great.

_KurT_’s picture

Status:Needs work» Needs review
new7.13 KB
PASSED: [[SimpleTest]]: [MySQL] 160 pass(es).
[ View ]

Add triggering on empty\filled condition, seems like now it works.
Include patch #63

michielkenis’s picture

The patch in #74 seems to work except I get an warning:

Warning: array_values() expects parameter 1 to be array, null given in _field_filter_items() (line 502 of /Users/*/Sites/*/modules/field/field.module).

I traced it back to this line in the patch:

$input_state = drupal_array_get_nested_value($form_state['values'], $dependent['#parents']);

It should return an array, but I got NULL. I'm using an Entity Reference as field.

So I added an extra line right below:

$input_state = (is_null($input_state)) ? array() : $input_state;

Which seems to fix this issue in my case!