Hi,

I am using conditional fields in conjunction with the paragraphs module.
I created a node type with one paragraphs field and several paragraph bundles that can be added to this field.
On one of these bundles I created the following dependencies:
- if radio button field A has value 1, then list field B is required;
- if radio button field A has value 1, then list field B is visible;
- if radio button field A has value 2, then list field C is required;
- if radio button field A has value 2, then list field C is visible.
This works perfectly for the first paragraph of this bundle that is added. However any subsequent paragraph of this bundle doesn't check its dependencies.

Possible causes:
- conditional fields only works once per page;
- the check is base on the field config name, instead of the HTML name, which is unique;
- something else?

I guess this might be causing issues with other modules that reuse fields on the same page as well, but I am not aware of those.

CommentFileSizeAuthor
#3 conditional_field.2530770.patch4.41 KBemmanvazz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alejandrovaquero’s picture

I think this issue is also affecting Inline Entity Forms module. When editing two or more IEF in the same parent form, only the first IEF get conditional fields working.

There is a check in conditional_fields.module to not reattach on the same field_name:

      if (!isset($form['#conditional_fields'][$field['#field_name']]['dependees'][$id])) {
        conditional_fields_attach_dependency($form, array('#field_name' => $dependency['dependee']), $field, $dependency['options'], $id);
      }

But removing that check makes conditionals not to work even in the first field, so not sure the proper way to address this issue.

efrainh’s picture

I'm having the same issue. I created a paragraph and set some conditions, they work fine on the first paragraph but when i add more, the conditions don't work anymore.

emmanvazz’s picture

The issues is with writing to the $form['#conditional_fields'] array. This is my solution for this. I am using the alpha branch. Works for me. Hope this helps.

JordanMagnuson’s picture

After some very basic initial testing, the proposed patch seems to be working for me. Need to test more thoroughly, but initial thumbs up!

JordanMagnuson’s picture

Note: the patch in #3 does not apply cleanly to current dev.

JordanMagnuson’s picture

First of all, thanks for the patch in #3! Very much appreciated! It seems the patch is partly functional, but is not quite working with dependent fields that are also required.

My use case:
1) I have a content type with an required entity reference field that is dependent on a required Boolean radio field being set to true ('does this item need references? yes or no -> if user clicks yes, then the entity reference field becomes visible, and required). See screenshot: http://i.imgur.com/RqbhbLd.png

2) I have multiple node_add forms for this content type displayed on a single page, via the Bulk File Nodes module.

3) This patch makes the conditional fields show and hide correctly for each node form: if I click "yes" on the radio button on any of the forms, the reference field displays for that form, as it should.

4) However: the required field functionality is broken: if I click "yes" on a radio button on one of the forms, the conditional entity reference field becomes visible and required on that form as it should--but the reference field also becomes required on all the other forms, even when the condition for the field to display is not met on the other forms.

In other words: if the condition to display the field on any of the forms is met, it makes the dependent field required on all the forms, even the ones where it is still hiding (where the condition has not been met).

emmanvazz’s picture

Yeah the fields I was working on are not required so that could be the case. Hopefully my patch can point you towards the right direction on where the fix for that would be.

JordanMagnuson’s picture

Status: Active » Needs work
drclaw’s picture

Status: Needs work » Closed (duplicate)

I believe this is a duplicate of #1464950: Support for multiple "Field collection" and "Multifield" fields which currently has a working patch:

That issue was originally for field collections, but the fix works for paragraphs as well (and probably IEF too!)

HansKuiters’s picture

Thanks @drclaw for pointing to the other issues. I used the patch for 7.x-3.0-alpha2 to solve my issue.