I have a field collection (B) that is set within another field collection (A). I am trying to toggle the visibility of B using another field that is also in A. I have set up an appropriate dependency but toggling the field has no discernable impact on the field collection.

I have disabled all other modules to check for compatibility issues but this does not improve the situation. I am able to get the desired functionality within a field collection if both the dependent and dependee are fields. But not when the dependent is a field collection and the dependee is a field. I am also able to get the desired functionality if i move field collection B and the dependee field outside of their parent field collection and into the top level of the content type. It is only when i try to do this within another field collection that i am experiencing the above behavior.

I am not super familiar with conditional fields but if someone could point me in the right direction i would be more than willing to look into this.

Comments

Same problem...

i have same issue.

project i am on will fund getting this to work if anyone wants to tackle it; or will look at it myself when i get a chance.

@liquidcms

we have some extra bandwidth and would be more than willing to tackle the issue if you could get some fundtion for it!

@pirog contact me at peter@liquidcms.ca

starting to dig into this a little and right off the bat i see issue appears to be that in conditional_fields_form_after_build() the dependency info is looked at for each field that has been assigned as dependent; and for my field there is no dependee info set; so function exits - and no JS is loaded.

it is this code that fails for the dependee field (field collection trying to be made invisible based on simple list field):

<?php
 
// Some fields do not have entity type and bundle properties. In this case we
  // try to use the properties from the form. This is not an optimal solution,
  // since in case of fields in entities within entities they might not correspond,
  // and their dependencies will not be loaded.
 
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;
  }
?>

which returns the wrong values to pass for this:

<?php
$dependencies
= conditional_fields_load_dependencies($entity_type, $bundle);
?>

and sure enough, if i statically force in the right values; everything works fine.. :) so just need to figure out the additional cases required for that clause to pull the correct $entity_type and $bundle values.

Status:Active» Needs review
StatusFileSize
new1.3 KB

i am sure this isn't the proper patch as i likely took a few liberties with my specific application; but should be a decent starting point.

my guess is my new test case is different than the one that i designed the patch above for; as it doesn't work in this case.

i switched around the 2 elseif clauses and it now works for my current case; but not sure it would still work for the case i originally had; my guess is it does.

The patch in #8 works great for me.
Thank you.

I ended up having to make a slight change in #8's patch to make it work with my setting, but I think this new patch should work for most if not all settings.

Patch in #11 worked - Jumping for joy; albeit more baldly now!

UPDATE

Please help roll this dual patch to a release: https://drupal.org/node/2088101

Issue summary:View changes

a little extra precision

Patch in 11 works for me.

There is still a slight problem in that if you have required fields that are triggered by conditionals, and you add another field collection, you can end up with two 'required' asterisks on your fields.