When editing/adding an entity that contains conditional fields via an Inline Entity Form, the conditional_fields.js is not included, disabling its functionality.

See: https://drupal.org/node/2186203

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kaushashah’s picture

Even I am facing the same issue. For administer, it is working fine but for non-admin, it doesn't show up the fields. Any solution to this?

kaushashah’s picture

Don't know how but by granting the permission of administer url alias, fields defined under conditional states started showing up.

sender’s picture

Version: 7.x-3.0-alpha1 » 7.x-3.x-dev
Status: Active » Needs review
FileSize
543 bytes

Here is a patch that loads conditional_fields.js in a different way.

Inline Entity Form now picks up on the JS, and the behavior is as expected.

Note: I don't use effects for conditional fields, and I didn't change the $form['#attached']['js'] for effects.

zmove’s picture

Status: Needs review » Needs work

Not working for me, can't make conditional fields working with an inline entity form added entity, even with this patch applied.

mihai_brb’s picture

The above patch changes the command to attach the main js file.
I made a test and forced that this file will be included on all pages but the conditions are still not working.

Isn't the problem with the next lines of code that add the effects?

// Add effect settings to the form.
  if ($effects) {
    $form['#attached']['js'][] = array(
      'data' => array(
        'conditionalFields' => array(
          'effects' => $effects,
        ),
      ),
      'type' => 'setting',
    );
  }
mihai_brb’s picture

Title: JS not loaded when using Inline Entity Form » Inline Entity Form compatibility
Component: Javascript » Compatibility w/ other modules

After further looking into this it seems that the problem is not with the fact that the main module main JS file is not loaded. As far as I see the functionality is not given by the main JS file, but by the Form API #states.

From my tests, the problem is here:

if (isset($field['#entity_type'], $field['#bundle'])) {
    $entity_type = $field['#entity_type'];
    $bundle = $field['#bundle'];
  }
  elseif (isset($form['#entity_type'], $form['#bundle'])) {
    $entity_type = $form['#entity_type'];
    $bundle = $form['#bundle'];
  }
  else {
    return $element;
  }

  $dependencies = conditional_fields_load_dependencies($entity_type, $bundle);

If it fails to get the entity type and bundle from the element, it will take this info from $form. In case of IEF fields, this is not correct, because the form is for the field that references the entity fields. This will lead to out of context conditional_fields_load_dependencies().

Patch is on the way.

Regards,
Mihai

mihai_brb’s picture

Status: Needs work » Needs review
FileSize
839 bytes

OK, in my case this fixed dependent fields triggering.
I have tested with one/multiple entity reference values and both IEF single/multiple values widget.

More info:
I have a Node, referencing products. Products have a Boolean field, triggering the visibility of another field.

Are there any other cases to be tested?

Mihai

Status: Needs review » Needs work

The last submitted patch, 7: conditional_fields-IEF_compatibility-2193025-#7.patch, failed testing.

mihai_brb’s picture

Status: Needs work » Needs review
FileSize
627 bytes

wops, forgot to create the diff on the module repository ...

yannickoo’s picture

Status: Needs review » Patch (to be ported)

Worked fine for me, thanks!

minorOffense’s picture

Why is it only choosing field[0] ?

yannickoo’s picture

I think it's enough to load the JavaScript once, after the necessary files have been loaded it can not break anymore :)

mansspams’s picture

Add that in comment above lines? Its a legit question.

mansspams’s picture

Reupload without # character in patch name to work on Windows drush make.

millerengage’s picture

#14 works for me.

It's been 8 months. Can this be added to the release yet?

silurius’s picture

This has been ready for porting for 2 years. What's the plan?

Topplestack’s picture

This same problem exists for D8. I've created a ticket for it here:

https://www.drupal.org/node/2856720

Part of the issue in D8 is the removal of drupal_add_js() in favor of $form['#attached'] which doesn't seem to be working in this situation.

delacosta456’s picture

hi
this is not working for commerce kikstart when using conditional field on an IEF on product variation

mikestar5’s picture

I applied patches #3 and #9 and it still isn't working with a node that has several IEF fields...

Does anybody know why this is happening?

conditional_fields.js is now being loaded on IEF actions... but still unresponsive when loading more than one IEF field.

thanks

dqd’s picture

Status: Patch (to be ported) » Closed (duplicate)

Thanks for the reports and all the hard work in here. But due to inactivity in this issue for years and because of the upcoming EOL of Drupal 7 soon I will close this issue while cleaning up the issue queue. Check the related issue top right, there is a fix to be committed soon for Drupal 8 and above.