Support for multiple "Field Collection" fields to have a dependency on all instances of the fields within that collection. For example, say you create a "Field Collection" field and checked it to have the "Number of values" set to unlimited. Then you configure the "Field Collection" field to have a checkbox and textarea field attached. When you would check the "checkbox" field you would like to then display the textarea field which you setup using the "Conditional Fields" module interface. This all works for the first instance of the "Field Collection" field. When you start creating multiple instances using the "add another item" button, the checkbox condition will not work for those additional instances. Does any one have any suggestions on how I can go about implementing this?

Thanks,
Droath

Files: 

Comments

same happens here.

Issue summary:View changes

Updated explanation of feature

Hi, I also have the need for this functionality.

Status:Needs review» Active

I have a patch that adds this functionality, I will be releasing it here soon...

Status:Active» Needs review
StatusFileSize
new21.93 KB

Here is the patch that implements this functionality described above.

I rerolled the patch so It could be applied from the "conditional_fields" module directory.

Status:Active» Needs review

Can't wait to test this!

Side question, would your patch possibly solve this issue as well? #262453: Grouping dependencies by dependent with OR/XOR evaluation

i try to apply the patch online through: http://owl.cs.manchester.ac.uk/patch/patch-form.php
but the problem for the "Field Collection" fields remained.
i have the condition set by using an select box, it only works for the first item in the collection ....
any suggestion for me ?

@rhiss

Can you confirm the patch was applied correctly using the third-party patching tool? If your familiar with git, you can read how to apply patches here: https://drupal.org/node/707484. It's about 3/4 way down the page, where they tell you how to apply a patch.

How many "field collection" fields are attached to the entity your working with? I have only tested with one "field collection" field attached to a node entity, but the "field collection" also has another "field collection" field attached to it as-well. On that second collection is where I have the conditional field module configured to manipulate the form. Let me know if you have a different situation, and I will adjust my patch if needed.

@animelion

I will look and see if this patch can help resolve issue.#262453: Grouping dependencies by dependent with OR/XOR evaluation

droath thx for your attention. after checking the online-patched version i noticed, nothing was patched.
i tryed patching with git, both of you versions, from root and module dir but i get errors like "warning: squelched 26 whitespace errors
warning: 31 lines add whitespace errors." i m not so familiar with patching but i could try to do it manualy, or you could post your patched module file here, would be great!
basicly what i want to do is to have one "field collection" on a node with diffrent fields(image, file, long text,... ) and select on each added entity instance which fields i want to edit. it should become some flexible content node without content syling in the RTEditor.
i know there are other ways to do it with entity types, but with the Conditional Fields Module and FieldCollections it should work as well!

Patch in #6 fails completely

conditional_fields_fixed_multiple_field_collection_fields_1464950-5-1.patch:19: trailing whitespace.
conditional_fields_fixed_multiple_field_collection_fields_1464950-5-1.patch:29: trailing whitespace.
conditional_fields_fixed_multiple_field_collection_fields_1464950-5-1.patch:32: trailing whitespace.
    $field_parents_string = _conditional_fields_flatten_array(array_filter($field['#field_parents'], 'is_numeric'));
conditional_fields_fixed_multiple_field_collection_fields_1464950-5-1.patch:61: trailing whitespace.
      $array_string .= $separator;
conditional_fields_fixed_multiple_field_collection_fields_1464950-5-1.patch:126: trailing whitespace.
  foreach ($form['#conditional_fields'] as $parent_dependent_key => $parent_dependent_info) {
error: patch failed: conditional_fields.module:264
error: conditional_fields.module: patch does not apply

I tried patching manually, but there are just way to many differences in the code. It looks like the latest version of CF changed quite a bit, thus making the pacth obsolete. Bummer.

Thanks for doing it thought.

This patch has been altered to work with conditional_fields 7.x-3.x-dev (2012-Apr-13).

The issue that I uncovered was that we were not storing multiple conditional fields in $form['#conditional_fields'], just data for the first conditional field, which is delta 0.

For instance, say we had field $element[foo][und][0] this would index the $form['#conditional_fields'] array by the dependees/dependents field name, so it would be like this: $form['#conditional_fields']['foo'][...][...].

So when $element[foo][und][1] tried to join $form['#conditional_fields'] array it wouldn't be able too, since we were already storing that data for the dependees/dependents foo field.

The way I implemented it in the patch was by indexing the $form['#conditional_fields'] array by the field parents flatten array. So that it could accommodate for multiple conditional fields, since it now has a unique field key. So now $form['#conditional_fields'] stores data like this:

  $form['#conditional_fields'][foo:und:0][foo][...][...]...
  $form['#conditional_fields'][foo:und:1][foo][...][...]...
  $form['#conditional_fields'][foo:und:2][foo][...][...]...

Since we are now storing the field parents as a flatten key, we could then remove $form['#conditional_fields'][foo:und:0][foo][parents] array, as that's the same data collected twice. But I'll leave that up to the module maintainer.

Let me know if you have any issues with this patch, or If anyone has a better solution on how we can accommodate for this functionality.

Category:support» feature

Was this commited to the 17th dev release? Just wondering

Thank you very much for the reply and the patch.

I tried applying it on the 17th dev release, it failed. I know you say it was made for the 13th one, but I tried it.

Hunk #7 FAILED at 465.
1 out of 8 hunks FAILED -- saving rejects to file conditional_fields.module.rej

same here. i tried patching the last conditional_fields 7.x-3.x-dev (2012-Apr-17). didnt work.
am i missing something, is there a version 7.x-3.x-dev (2012-Apr-13)?

Status:Needs review» Reviewed & tested by the community
StatusFileSize
new15.26 KB

I was able to apply the original patch against the 4/13/2012 -dev version (git commit b10aa5aa310). I found a "}' was missing on line 627.

The attached patch is re-rolled against the 7.x-3.x HEAD (git commit d905202fad), which is likely one commit ahead of the 4/28 -dev version on the project page right this moment.

The attached patched worked great for me. I tested in on a 3 field field collection. My first field was select box, the 2nd and 3rd fields in the collection were check boxes. I set-up my dependencies respectively between the 1st, 2nd and 3rd fields and all worked great.

Status:Reviewed & tested by the community» Fixed

Looks like it's already in the repo as of 4/24, marking this fixed. It should be in the May 1st -dev tar ball.

Status:Fixed» Needs review

sorry I jumped the gun doesn't look like it's actually fixed yet

LAtest patch seems to have been added to latest release. (patching reports no changes)

Hi,

It seems that your patch references a file named "states_enhancements.js" that I do not find. Did you modify the states.js file to fix this bug ?

(and of course thanks for the work !)

@rfc2460 > states_enhancements.js is in conditional_fields.js.

Conditional Fields: May 2, 2012 3:41
Commit 8718f66 on 7.x-3.x
by peterpoe

Consolidated states_enhancements.js and conditional_fields.effect.js in a single conditional_fields.js and rewritten states override.

http://drupal.org/node/206178/commits

I'm not having any luck applying the patch from #18 to the current dev version, and as far as I can tell, it's not implemented. Anyone else have it working?

I'm unable to either. Anyone else have luck?

I was able to apply manually #13 to the current dev version (2012-May-05).
It works for multiple field collection, but stop working for fields outside a field collection.
I suppose the problem is Null returned by function conditional_fields_flatten_array in case of fields width no #field_parents.

My quick&dirty solution is to change:

function conditional_fields_flatten_array($array, $delta = 0, $separator = ':') {
-  $array_string = NULL;
+  $array_string = 'root'.$separator;

controls like this
     if (isset($field_parents_key)) {
are now useless, but not a problem.

it seems to work.

@guidotti, Would be lovely if you can share your patched code. I want to test if is working as well . Thanks in advance :)

This is the patch for 7.x-3.x 2012-May-05
There is a problem validating required fields that are not visible according to dependency rules.

Thank you @guidotti and @droath

Patch from #28 works on dev branch 7.x-3.x 2012-May-05 (commit 0a9f967ffbea277fcd6ecf1ea4ba20da9503fd6c)

Patch at #28 applies and works as expected, but adds whitespace errors for me:

$ git apply -v conditional_fields_fixed_multiple_field_collection_fields_1464950-28.patch
conditional_fields_fixed_multiple_field_collection_fields_1464950-28.patch:18: trailing whitespace.
conditional_fields_fixed_multiple_field_collection_fields_1464950-28.patch:93: trailing whitespace.
conditional_fields_fixed_multiple_field_collection_fields_1464950-28.patch:120: trailing whitespace.
conditional_fields_fixed_multiple_field_collection_fields_1464950-28.patch:123: trailing whitespace.
conditional_fields_fixed_multiple_field_collection_fields_1464950-28.patch:127: trailing whitespace.
Checking patch conditional_fields.module...
Applied patch conditional_fields.module cleanly.
warning: squelched 22 whitespace errors
warning: 27 lines add whitespace errors.

I applied the patch with this command and didn't get errors or warnings.

$ patch --verbose -p1 < conditional_fields_fixed_multiple_field_collection_fields_1464950-28.patch
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff --git a/conditional_fields.module b/conditional_fields.module
|index 497d1e6..8c05766 100644
|--- a/conditional_fields.module
|+++ b/conditional_fields.module
--------------------------
Patching file conditional_fields.module using Plan A...
Hunk #1 succeeded at 231.
Hunk #2 succeeded at 273.
Hunk #3 succeeded at 290.
Hunk #4 succeeded at 369.
Hunk #5 succeeded at 400.
Hunk #6 succeeded at 415.
Hunk #7 succeeded at 444.
Hunk #8 succeeded at 1012.
Hunk #9 succeeded at 2004.
done

#31 working where git apply isn't. thanks!

With the latest dev version, I'm now getting:

$ patch --verbose -p1 < conditional_fields_fixed_multiple_field_collection_fields_1464950-28.patch
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff --git a/conditional_fields.module b/conditional_fields.module
|index 497d1e6..8c05766 100644
|--- a/conditional_fields.module
|+++ b/conditional_fields.module
--------------------------
Patching file conditional_fields.module using Plan A...
Hunk #1 succeeded at 231.
Hunk #2 succeeded at 273.
Hunk #3 succeeded at 290.
Hunk #4 succeeded at 369.
Hunk #5 succeeded at 400.
Hunk #6 succeeded at 415.
Hunk #7 FAILED at 444.
Hunk #8 succeeded at 1012 (offset 2 lines).
Hunk #9 succeeded at 2000 (offset -2 lines).
1 out of 9 hunks FAILED -- saving rejects to file conditional_fields.module.rej
done

Anybody have this working on a newer version?

why always new patches? i would like to see a working patch in the next dev update.

can we has this features in latest dev version or can somebody provide a new patch?

i also have this issue...multiple group and conditional field not working properly....

@wrd

were you able to get this patch to work ? http://drupal.org/node/1464950#comment-6122020

I actually got the same error as you ?

thanks

Nick

Thanks naeluh, but actually i have drupal 6.2x proublem, sorry to post in wrong place....

I'm having problems with the patch and the latest dev version, too. Tried to manually patch it up, but there are too many code differences.

I am having the Hunk 7 failed at 444 as well when applying the patch to the latest (July 30) dev version. Any chance of getting a new dev build with the patch included? Or help on fixing the patch would also be appreciated!

Here is a patch file off latest dev using git, cheers.

May be a misplaced bracket in last patch...welcome to try this one.

@joel_osc

I will try the patch and report back

thanks for your help !

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

Great, #42 works great.

Yep, the patch from #42 is working! Thanks!

#42 along with the #1 patch http://drupal.org/files/conditional_fields-support_for_markup_field-1786... at http://drupal.org/node/1786232 has allowed conditional fields to work with Commerce Registration and Field Collections here.

Status:Needs review» Needs work

I tested the patch in #42 and it solves the problem for the conditional fields inside a field collection. But after that the conditional fields for the regular fields on all node types stopped working.
I traced this back to somewhere around line 260 in conditional_fields.module. The patch adds a variable $field_parents_key to point to the fields inside the field collection, but if this is only root: it should not be added.

The workaround I came up with is adding a check for the value of this variable. But this doesn't seem like a really clean solution.

      // Only add the field parents key if it is not only root:.
      if ($field_parents_key == 'root:') {
        if (!isset($form['#conditional_fields'][$field['#field_name']]['dependees'][$id])) {
          conditional_fields_attach_dependency($form, array('#field_name' => $dependency['dependee']), $field, $dependency['options'], $id);
        }
      }
      else {
        if (!isset($form['#conditional_fields'][$field_parents_key][$field['#field_name']]['dependees'][$id])) {
          conditional_fields_attach_dependency($form, array('#field_name' => $dependency['dependee']), $field, $dependency['options'], $field_parents_key, $id);
        }
      }

I am seeing a problem with conditional fields outside of field collections as well. I am not sure if it is the same as @alduya - the symptom is that none of the info I type into my dependent fields gets saved. I think @alduya might be on to something with the above code, however when I added it the fields on the form were no longer displayed as conditional - they were all displayed. I think this is a result of the first call to conditional_fields_attach_dependency:

conditional_fields_attach_dependency($form, array('#field_name' => $dependency['dependee']), $field, $dependency['options'], $id);

...where the $field_parents_key argument is ommited and $id is passed in as the field parent.

The problem I have is indeed that the value of the dependent field does not get saved.
I also added the check of my previous post to the code for that attaches the dependent; which fixes the conditional behaviour. But then there came errors from theconditional_fields_evaluate_dependencies which I could not get around.
Are there people who know this module better who can help out here? The patch in #42 solves the issue for conditional fields in field collections, but breaks conditional fields outside field collections.

Sorry, correction and clarification.
I first only added the check to the code that attaches the dependent (line 278). But that broke the conditional behaviour.
Then I also added the check to the code that attaches the dependee (line 290). This fixes the conditional behaviour, but the validation gives errors.

Category:feature» bug

I have applied the patch in #42, and it works for the most part, but it doesn't affect field collections inside a field collection. The Or condition also doesn't seem to be working.

#42 works with a multiple field collection for me

It is possible to get a copy of the module after patch #42 has been applied. Would any one please share the zip file?
I am not skilled to use git.
Thanks

Has anyone had any luck applying this patch to the latest version? It doesn't even patch for me.

Priority:Normal» Critical

Has anyone found any solution? We would like to chip in if anyone could solve the issue and provide a patch.

I found a work around: using field collection and conditional fields modules I am able to hide collection of fields based on dependee field's value.

a field collection is normally attached to a host entity,hence a generic entity support is required
in my case my field collections are attached to profile2.
hence i would need conditions on two entities
1. field collection fields as fields on profile2 and mange dependencies as field collection fields as fields
2. manage dependencies of fields of a field collection item
3.manage dependencies of fields across field collection items i.e irrespective of entity they are attached to, in my case all
So, at the profile2 level the filed list includes
1. all the field collection items as field names (they are fields with respect to profile2)
2. all the fields of all the field collection items
3. any fields directly attached to profile2

Patch from #42 applied (albeit with whitespace errors) against the dev commit from July 29, 2012 with hash de8d798ffc3d976f1ad4302b7b0af086e825a26d.

To anyone needing this functionality who is not that familiar with git (note that this will break your site for a minute or so):

0. Put your site into maintenance mode if you're concerned about users getting WSODs (Not that you really should use patched modules on a production site, but that's a discussion for another day).

1. Backup your existing conditional fields directory by moving it into sites/all (I.e., one directory below "modules" -- feel free to create a directory like sites/all/disabled to put it in if you prefer).

$ mv conditional_fields ..

2. Run the following:

$ git clone --recursive --branch 7.x-3.x http://git.drupal.org/project/conditional_fields.git

$ cd conditional_fields

3. Once in the newly-cloned conditional fields directory, checkout the older dev version:

$ git checkout de8d798ffc3d976f1ad4302b7b0af086e825a26d

How did I get that version hash? git log shows all commits in the branch.

4. Download and apply the patch from #42:

$ wget http://drupal.org/files/conditional_fields_fixed_multiple_field_collection_fields_1464950-42.patch

5. Apply using git:

$ git apply -v conditional_fields_fixed_multiple_field_collection_fields_1464950-42.patch

I haven't really had to checkout an older dev version to get a patch to apply before, figured I'd document the process in case it helps someone!

Thank you Aendrew, your steps work for me.

@jason.fisher (#47), I've been working on Commerce Registration for a client, and that's why I wrote the markup field patch. I'm going to look at the patch in #42 and see about updating it to apply to the latest commit in the repo, so you won't need to follow aendrew's instructions (#59).

Here's the updated patch, tested it for an event with two registrations in Drupal commerce.

Status:Needs work» Needs review

Title:support for multiple "Field Collection" fieldsSupport for multiple "Field Collection" fields.

Thanx for sharing Andrew ;)

@arosboro -- Thanks for doing that! I can confirm that it patches cleanly against 7.x-3.x, revision hash ec8fdd9adcf942337e07b66157d159c418923bbb.

@ arosboroIts great work and thanks,
still this needs this mentioned at# #58 the

2. all the fields of all the field collection items

dependent and dependees listing of all the fields of all the field collection items attached to host entity eg:hostEntity - profile2 profile

Status:Needs review» Reviewed & tested by the community
StatusFileSize
new22.5 KB

Fixing the patch file by removing 'a/' and 'b/' to prevent the error (can't find file to patch at input line 5) when using drush with .make file.
Otherwise it works as it should.

I can confirm that this patch applies to 7.x-3.x-dev (2012-Nov-12) and works correctly.

#67 works for me on 2 different installs.

Status:Reviewed & tested by the community» Patch (to be ported)

I don't know about you folks, but I'm so excited by this most recent status update that I can barely sit still. :)

Priority:Critical» Normal

Those who are getting the patch to work, are you setting the dependencies on the content type or the field collection? Even with the patch, the dependencies don't seem to be working when a field collection within a field collection depends on the value of another field. Here's my setup:

I have a field collection called "Main Content Well". Within this field collection, I have an image field, and another field collection called "Content Section" (the content manager can add as many as he wants of these). This content section has a select list, and different fields should appear/disappear based on the selected option. For example, if from the select list they select "Youtube video", all of the field except for the youtube video field should disappear. This works fine for single fields, but for field collections, they won't hide. Is this what this patch is fixing? Or is this another issue?

Has somebody already applied the patch successfully? I'm getting an error.

can't find file to patch at input line 5
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/conditional_fields.module a/conditional_fields.module
|index 31c76ec..60167ad 100644
|--- conditional_fields.module
|+++ conditional_fields.module
--------------------------

Try removing a/ and /b in the 1st line.

Removed the 'a/' and 'b/', but I am getting the same error.

can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git conditional_fields.module conditional_fields.module
|index 31c76ec..60167ad 100644
|--- conditional_fields.module
|+++ conditional_fields.module
--------------------------

Also tried it without the a/ and b/ but same problem here as #75

try:

patch -p0 < file.patch

?

Applied the patch from #67. Re-uploaded the module. Saw no warnings, but also saw no change. What am I missing?

#72 - your explanation is confusing, maybe you can provide a screeenshot?

Anyway I just tested the #67-patch with field collections within field collections and everything works just fine.

Kudos to guys in the issue queue, that made it work. It's been a long fight.

Thank you for your explanation aendrew :) this thread solve my problems

Thank you so much for that very helpful fix #67 worked very well for me. Just re-uploading a cleaner patch, taking out the 'trailing whitespaces' error.

Kindly review if this works okay.

#81 patch is actually the only patch that was working for me.

However nested field collections with a dependency does still not seem to work on my site.
Is it in the scope of this patch or should I create a new issue?

we tried #81. it doesn't work.
we applied the patch directly. without using git.
Any other possibilities is there?

Maybe it helps maybe not.

My steps were:
Uninstall module
Delete folder /sites/all/modules/conditional_fields
Download latest 7.x-3.x-dev
Install it
(I used patch manager)
Add the patch
Applied the patch

@in1ventures, could you try clearing your cache and see if that helps?

@rbosscher, re nested field collection, perhaps it will be cleaner to create a new issue for this?

It worked for first field collection. But it is not working with nested field collection fields.
Any other possible solutions is there?please give us.

StatusFileSize
new30.92 KB

I've done a bit of searching.
Seems that nesting field collections issue is arround a while in 6.x versions as wel in 7.x

For: 7.x
The nested field collections are addressed in #1683136: Multiple Field Collections not displaying properly when using Conditional Fields but is pointing to this issue.
The issue starter of #1886628: How do i create nested dependent fields? is probably also refering to nesting field collections.

Not sure that this issue is about nesting fields, but could be a solution #1398482: you can specify parent relationships
As soon as I have some time I'll have a look at that one.

@opensoft1
On the module name field, did you filed it in as the module machine name?: "conditional_fields"
Your patch is being applied at sites/all/modules/contrib/conditional_fields while it probably should be applied on sites/all/modules/conditional_fields

we tried #88.
It doesn't work to us.

our requirement is

field collection 1
---field1
---field2
---field collection2
--- field1(checkbox)
--- field collection3

if clicked field1 of field collection2,field collection3 should be show otherwise it should be hide. This is our requirements. How can we achieve this through conditional fields?.
Is there any possible solution? Please guide us.

hi..... Is there any updates for this issue? pls kindly request you to give some solution for this issue

Having the same issue: I can have a field collection dependent on another field in a content type. But if I try to create the same thing within another field collection, nothing happens; the dependent field collection is visible always and changing the dependee field seems to do nothing. Interestingly, if I have both of these situations on a form (a field collection dependent on a top-level field, and a nested field collection dependent on a field in the top-level field collection), both work as expected. Perhaps the required JS simply isn't being loaded when the form's only dependency is in a nested field collection. I don't see any errors in my browser's console.

Status:Patch (to be ported)» Reviewed & tested by the community

Any progress on committing the #81 patch?

Patch from #81 applied cleanly for me using git apply against the 2012-Nov-12 7.x-3.x-dev snapshot

Patch in #81; RTBC++ Thanks for all the hard work on this issue!

Regarding #86, #89, and #91 (supporting nested field collections) -- the patch is already pretty big and hard to review, so I suggest dividing it out into a second followup issue, so that it doesn't block this patch from forward progress and making it into the code-base as is.

I've created a patch for cross-entity dependees, see #1995516: Cross entity (Inline Entity form and Field collection) dependees. It's probably far from perfect, but it might be a good start!

#81 worked for me for non-nested collections.

Category:bug» task
Priority:Normal» Critical
Status:Reviewed & tested by the community» Needs review
StatusFileSize
new46.04 KB

Hi, this version works fine with Field collection modules, and other modules, without bug when adding new field collection entries.

I just tested on 'required' feature on field collection. It works on the front end (shows the asterisk * ) but It doesn't actually validate on the form submit.
The 'optional' feature doesn't work either. Correct me if i am wrong.
Thanks

i test #97 in admin form but not work for me. i am using "conditional fields" for "profile 2" with "field collection".

i created two field collection with many fields inside and add this fields in profile and can create dependencies but when change radio box not works "hide/show".

please help me how can i use field set in conditional fields module.

i searched and find many issues about this problem. but not found any solution or patch.

any body can help?

thanks

StatusFileSize
new16.48 KB

Solving two issues with 2 patches

Issue #1 - This issue - Conditional Fields not working well with multi-value field collections.

Issue #2 - Nested field collections not responding as dependents on show/hide options (maybe others, but not tested)

To solve:

I combined #81 above with this other patch that solves for nested field collections.

Outcome:

It seems stable and working. I've attached the multi-patched version here. All you need to do is replace the .module file in the current dev release.

UPDATE

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

Priority:Critical» Major
Status:Needs review» Reviewed & tested by the community
StatusFileSize
new1.54 KB
new22.42 KB

+1 to jwilson3 words in #94:

Regarding #86, #89, and #91 (supporting nested field collections) -- the patch is already pretty big and hard to review, so I suggest dividing it out into a second followup issue, so that it doesn't block this patch from forward progress and making it into the code-base as is.

#81 is the latest working patch.

Patch in #41 introduces an extra + at line 294. None of the subsequent patches fixes it:

+++ b/conditional_fields.module
@@ -287,8 +289,8 @@ function conditional_fields_element_after_build($element, &$form_state) {
-      if (!isset($form['#conditional_fields'][$field['#field_name']]['dependents'][$id])) {
-        conditional_fields_attach_dependency($form, $field, array('#field_name' => $dependency['dependent']), $dependency['options'], $id);
+      if (!isset($form['#conditional_fields'][$field_parents_key][$field['#field_name']]['dependents'][$id])) {
++        conditional_fields_attach_dependency($form, $field, array('#field_name' => $dependency['dependent']), $dependency['options'], $field_parents_key, $id);
       }
     }
   }

Patch attached is #81 with this fix and a minor indentation fix. See interdiff.

I'm marking RTBC since #81 worked fine.

81,100 and 101:

Notice: Undefined index: #field_parents in conditional_fields_element_after_build() (line 278 in conditional_fields.module).
Warning: Invalid argument supplied for foreach() in conditional_fields_flatten_array() (line 2008 in conditional_fields.module).

And states not aplied for field.

Update:

States are aplied for all field in field collection, but i can create node without fill this fields.

Empty validator not working.

Status:Reviewed & tested by the community» Needs work

#102 Notice: Undefined index: #field_parents in conditional_fields_element_after_build() (line 278 in conditional_fields.module).

@divined what field types are you using in your field collection?

i have 3 fields:

1. selectlist (int) with 2 choices - "type of deal" (sell or rent)
2. field_collection with 2 subfields - "sell price"
- textfield (not required by default) - "price"
- selectlist (required by default) - "currency"
3. field_collection with 3 subfields - "rent price"
- textfield (not_required by default) - "price"
- selectlist (required by default) - "currency"
- selectlist (required by default) - "period of rent"

i have 4 dependencies rules:

1. "rent price" is visible when "type of deal" has value "2".
2. "rent price" is required when "type of deal" has value "2".
--
3. "sell price" is visible when "type of deal" has value "1".
4. "sell price" is required when "type of deal" has value "1".

---
Visible rule work as well.
Required rule mark not_required fields as required, but system not validate empty values
Required rule mark required fields with double asterisk

The patch in #101 is working well for me. Thank you all.

Status:Needs work» Needs review

@divined the problem you describe in #106 is not related to this issue. This issue is about multivalued field_collection fields.

Your setup fails in the same way with or without the patch here. You may open a new issue for the bugs with required fields within field_collection.

I'm unable to reproduce #105, thus moving back to needs review.

Issue summary:View changes

Fixed spelling

The patch from #101 does not work anymore and re-rolling is not funny but finally I did it :) I also uploaded a patch without all the whitespaces so that it is cleaner to see what the patch actually does.

BTW the patch works fine, thank you guys for the work!

Hello,

i get an error when i apply this patch (109) with git:

error: patch failed:conditional_fields.module:428

Thanks for your help.

#109 worked for me. Thank you.

I could apply the patch without any errors:

➜  conditional_fields git:(7.x-3.x) curl -O https://drupal.org/files/issues/conditional_fields-fixed_multiple_field_collection_fields-1464950-109.patch
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 22861  100 22861    0     0   7915      0  0:00:02  0:00:02 --:--:--  7915
➜  conditional_fields git:(7.x-3.x) ✗ git apply conditional_fields-fixed_multiple_field_collection_fields-1464950-109.patch
➜  conditional_fields git:(7.x-3.x) ✗

Patch rerolled (commit: 23eac31) and interdiff added.

Why did you re-roll the patch, the patch from #109 applies cleanly:

➜  conditional_fields git:(7.x-3.x) ✗ git apply -v conditional_fields-fixed_multiple_field_collection_fields-1464950-109.patch
Checking patch conditional_fields.module...
Applied patch conditional_fields.module cleanly.

@yannickoo:
Ok, no-test patch is failed:

conditional_fields (7.x-3.x %)$ git apply -v conditional_fields-fixed_multiple_field_collection_fields-1464950-109-no-whitespaces-do-not-test.patch
Checking patch conditional_fields.module...
error: while searching for:
  $state_handlers = conditional_fields_states_handlers();
  // Cycle all dependents.
  foreach ($form['#conditional_fields'] as $dependent => $dependent_info) {
      $states = array();
      if (empty($dependent_info['dependees'])) {
        continue;
      }
      $dependent_location = array_merge($dependent_info['field_parents'], array($dependent));
      $dependent_form_field = drupal_array_get_nested_value($form, $dependent_location);
error: patch failed: conditional_fields.module:428
error: conditional_fields.module: patch does not apply

The "no-test" patch was just the patch without whitespaces so that people can better see what the patch actually does.

Hello yannickoo,

After several attempts to patch I always get an error:

$git apply -v conditional_fields-fixed_multiple_field_collection_fields-1464950-109.patch
Checking patch conditional_fields.module...
error: while searching for:
    return $element;
  }
  // Attach dependent.
  if (isset($dependencies['dependents'][$field['#field_name']])) {
    foreach ($dependencies['dependents'][$field['#field_name']] as $id => $dependency) {
      if (!isset($form['#conditional_fields'][$field['#field_name']]['dependees'][$id])) {
        conditional_fields_attach_dependency($form, array('#field_name' => $dependency['dependee']), $field, $dependency['options'], $id);
      }
    }
  }
error: patch failed: conditional_fields.module:259
error: conditional_fields.module: patch does not apply

I also tried to patch the module at hand but I also have an error in the code.
Can you provide us the file patched?

Thank you for your help.

patch in 109 does not apply. using latest 7.x-3.x dev. says segment #6 (the largest section) doesn't apply.

Status:Needs review» Reviewed & tested by the community

So I got the patch in 109 to apply when I checked out the repo directly then applied the patch via git. So it appears it does still apply. It also works. Can this get checked in?

confirming patch in 109 works. thanks!

The patch in 109 works in Field Collections but breaks other Conditional Fields on my content type. When I go to save content in a Conditional Field that is not within a Field Collection the content is not saved. When I revert the module back to the original state (before the patch), everything works fine but of course I can't have Conditional Fields in Field Collections.

Anyone else run into this?

I get the error with patch #109 using Conditional Fields 7.x-3.0-alpha1 inside of Field Collections:
Hunk #1 succeeded at 272 (offset 13 lines).
Hunk #2 succeeded at 289 (offset 13 lines).
Hunk #3 succeeded at 368 (offset 13 lines).
Hunk #4 succeeded at 399 (offset 13 lines).
Hunk #5 succeeded at 414 (offset 13 lines).
Hunk #6 FAILED at 443.
Hunk #7 succeeded at 1001 (offset 15 lines).
Hunk #8 succeeded at 1984 (offset 9 lines).

jeffglenn, I continue to be unable to use conditional fields with multiple entries inside of a field collection

Here's a fun one:

If you have a multiple field collection inside of another (multiple) field collection, with the patch in 109, the inner field collections after the first one does not have working conditional fields.

So if you have field collection foo1 which contains collections bar1 and bar2, and you have field collection foo2 which contains collections bar3 and bar4, the conditional fields work properly in bar1 and bar 3 but not in bar2 or bar4...

rudongg: you need to pull the repo from git and then patch it. It will not work on any of the release branches.

Jody Lynn: while this indicates their are a few more bugs to fix this patch is a clear step forward I think it's important this patch gets put in asap. Then a new issue can be opened for that more specific case.

I'm getting the same issues as rudongg - Jody Lynn - how can you do that if you're not using Git? I simply downloaded the patch and in SSH I applied "patch -p1 mypatchfile.patch" and resulted in the Hunk #6 FAILED at 443.

Is there a way around this if you're not using git?

Thanks danielson, the patch applied cleanly. For others, here is the workflow:
1. git clone --branch 7.x-3.x http://git.drupal.org/project/conditional_fields.git
2. wget https://drupal.org/files/issues/conditional_fields-fixed_multiple_field_...
3. git apply -v conditional_fields-fixed_multiple_field_collection_fields-1464950-109.patch

response:
Checking patch conditional_fields.module...
Applied patch conditional_fields.module cleanly.

Thanks again for the patch!

I can confirm that pulling branch 7.x-3.x from git then using the patch works. I can now have Conditional Fields inside and outside of Field Collections and all works and content is saved.

Thanks rudongg for detailing!

Thanks, rudongg! I have provided the same steps that are in #127, but wrapped them in the "code" tag as as not to have the URL truncated and added the change directory as a step. Be sure you are in the target directory (sites/all/modules/contrib) before running the git clone command. If you don't have wget, go to the URL in the browser, download and then put the patch file in your conditional_fields folder -- you may have to remove the ".txt" at the end of the file name.

1. git clone --branch 7.x-3.x http://git.drupal.org/project/conditional_fields.git
2. cd conditional_fields
3. wget https://drupal.org/files/issues/conditional_fields-fixed_multiple_field_collection_fields-1464950-109.patch
4. git apply -v conditional_fields-fixed_multiple_field_collection_fields-1464950-109.patch

Patch applies cleanly, would love to see this in Dev! Thanks all!

Starting to see these notices/warnings after applying patch:

Notice: Undefined variable: options in conditional_fields_form_after_build() (line 558 of /Users/stephenm/Sites/devdesktop/capellicfree-dev/docroot/sites/all/modules/contrib/conditional_fields/conditional_fields.module).
Notice: Undefined variable: behaviors in conditional_fields_form_after_build() (line 572 of /Users/stephenm/Sites/devdesktop/capellicfree-dev/docroot/sites/all/modules/contrib/conditional_fields/conditional_fields.module).
Warning: in_array() expects parameter 2 to be array, null given in conditional_fields_form_after_build() (line 572 of /Users/stephenm/Sites/devdesktop/capellicfree-dev/docroot/sites/all/modules/contrib/conditional_fields/conditional_fields.module).
Notice: Undefined variable: options in conditional_fields_form_after_build() (line 558 of /Users/stephenm/Sites/devdesktop/capellicfree-dev/docroot/sites/all/modules/contrib/conditional_fields/conditional_fields.module).
Notice: Undefined variable: behaviors in conditional_fields_form_after_build() (line 572 of /Users/stephenm/Sites/devdesktop/capellicfree-dev/docroot/sites/all/modules/contrib/conditional_fields/conditional_fields.module).
Warning: in_array() expects parameter 2 to be array, null given in conditional_fields_form_after_build() (line 572 of /Users/stephenm/Sites/devdesktop/capellicfree-dev/docroot/sites/all/modules/contrib/conditional_fields/conditional_fields.module).

Hi,

I have applied the patch #109 with no errors. But this patch have introduced a bug in my form.

In my form (to add a node) I have a checkbox that controls if a collection fields must be visible or not. The collection fields is a multivalued field and into it there is a combo box that controls if a textbox is visible or not. The patch solved the dependencies problem into the field collection in case of more then one value (combo box - textbox), but now, when the form is submitted, the node created have the field collection always empty.

There is anybody that can point my on the right direction on where to check, in the trying to solved this bug?

update: every field collection present in content type and that is dependent from another field's state, it is not being saved in the node being created.

I have a content type, named A, with a field collection, named fc1. the fc1 field is dependent from another field (checkbox) named cb1. When cb1 is checked fc1 become enabled so that it is possible to fill its fields.

When the form it is submitted, the node is created but with a empty fb1 field.

does anyone can help?

tnks a lot
gmario

StatusFileSize
new22.53 KB
PASSED: [[SimpleTest]]: [MySQL] 160 pass(es).
[ View ]

Hi,

after a bit of debugging, i've found the reason of misbehaviour explained in the previous post. The patch of comment #109 inserts a bug

the code in conditional_fields.module before to apply the patch is

<?php
538
539       
// Add validation callback to element.
540        _conditional_fields_element_add_property($dependent_form_field, '#element_validate', 'conditional_fields_dependent_validate', 'append');
541      }
542
?>

after applied the patch

<?php
540       
}
541
542       
// Add validation callback to element.
543        _conditional_fields_element_add_property($dependent_form_field, '#element_validate', 'conditional_fields_dependent_validate', 'append');
544
?>

the function call _conditional_fields_element_add_property is put outside the brach "else" of "if" statement at row 497.

in attachment the new patch.

a si biri
gmario

Patch #132 worked for me but I had to apply it to latest dev release (7.x-3.x-dev 2014-Jan-06) to get it to work.

I can confirm that patch in #132 works as intended!

+1 for patch in #132. Applied cleanly against dev version from 06JAN2014 and works as expected.

The same here, patch in #132 worked correctly.

Works great. Thanks!

Patch #132 apply it to latest dev release (7.x-3.x-dev 2014-Jan-06) and starting to see these notices/warnings after applying patch:

Notice: Undefined variable: options in conditional_fields_form_after_build() (line 558 of /home/khasmir/www/meif/sites/all/modules/custom/conditional_fields/conditional_fields.module).
    Notice: Undefined variable: behaviors in conditional_fields_form_after_build() (line 572 of /home/khasmir/www/meif/sites/all/modules/custom/conditional_fields/conditional_fields.module).
    Warning: in_array() expects parameter 2 to be array, null given in conditional_fields_form_after_build() (line 572 of /home/khasmir/www/meif/sites/all/modules/custom/conditional_fields/conditional_fields.module).

Does anyone can help?
Thanks

Hi,

We've applied the patch in #132 but are experiencing the warnings originally reported in #102, specifically we're getting:

Notice: Undefined index: #field_parents in conditional_fields_element_after_build() (line 262 of /var/www/html/sites/all/modules/patched/conditional_fields/conditional_fields.module).
Warning: Invalid argument supplied for foreach() in conditional_fields_flatten_array() (line 1986 of /var/www/html/sites/all/modules/patched/conditional_fields/conditional_fields.module).

The field that's throwing the error is a views reference field on the main node. It appears that this field does not have #field_parents set at all. We don't have any dependencies set involving this field, so not sure if conditional fields needs to process the field.

I suspect the bug could be worked around in our case by moving the
$field_parents_key = conditional_fields_flatten_array($field['#field_parents']);
inside the

if (isset($dependencies['dependents'][$field['#field_name']])) {
and
if (isset($dependencies['dependees'][$field['#field_name']])) {

blocks, but not sure if that's the right fix or not.

Status:Reviewed & tested by the community» Needs work

Setting back to needs work, as these warnings aren't thrown without the patch. Happy to provide further info, or test alternative approaches / patches.