Currently, if a dependent field has more than one dependee, the dependency is triggered only if all its dependees satisfy the condition.

Users should be able to group dependees by dependend and decide the grouping logic (AND, OR or XOR).

Original Issue

It is a stated limitation of Conditional Fields that multiple controller fields do not work. Currently it will let you specify multiple controller fields for a single field. However, the controlled field is activate/inactive according to only the last controller field that was toggled.

e.g., I have a controlled field and two radio-buttons controller fields:
Controller 1:
( ) Red
( ) Green <-- Controlling value
Controller 2:
( ) Red
( ) Green <-- Controlling value

I now perform the following actions in sequence.
1. Choose Green for Controller 1, the controlled field displays. GOOD.
2. Choose Green for Controller 2, the controlled field is still displayed. GOOD.
3. Switch Controller 2 to Red, the controlled field is hidden. BAD. (Since Controller 1 is still Green, I would expect the controlled field to still be displayed.)

Proposed behavior:
Multiple controller fields function as a logical OR for determining whether the controlled field is displayed. e.g., (Controller 1) || (Controller 2) || ... || (Controller n). Currently whether to display or hide is decided just according to the state of the last-recently-toggled controlled field.

(Maybe this could be implemented with an up/down counter: Whenever a controlled field's controlling value is selected, increase the up/down counter. When a controlling value is deselected, decrease the up/down counter. When the counter hits 0, hide the controlled field.)

Is there anything I'm not considering here? Are there any other issues that make multiple controller fields hard to implement?

Comments

peterpoe’s picture

You correctly described the javascript part. To implement the feature, we should also change the logic of node view.

Idea: it would be nice to also let users define the logical operator: AND / OR.

peterpoe’s picture

Version: 5.x-2.x-dev » 5.x-1.x-dev
loze’s picture

subscribe

loze’s picture

subscribe

loze’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
StatusFileSize
new4.71 KB

I reworked the javascript to allow multiple controlling fields.
however, I didn't touch the node view logic or letting the user define the logical operator (yet).

I'm not sure if this is the approach that you want to use, and it can probably be optimized.
What this does, is on each field change, loops through all the controlling fields and sets a flag for the controlled field, if any one of the controlling fields values should trigger the controlling field. Then it calls showField and shows / hides the controlled Field depending on the flags value.

It's working for my limited purpose, and should for the above scenario.
just replace the conditional_fields.js with this file.
I've only tested it with d6.

loze’s picture

Status: Active » Needs review
dan_theman’s picture

Status: Needs review » Patch (to be ported)
StatusFileSize
new11.6 KB

Hi there,

For my application the file from loze did not the job, so i implemented the multiple controller functionnality. I didn't tested exhaustivly, but il should work in most of the situations. It works for sure for my application! The logic between controlling field is a logical AND. For exemple if you have :

A field
choice 1 ()
choise 2 () -->controlling value

B field
Choice 3 ()
Choice 4 () -->controlling value

C field (controlled field)
Choice 5 ()
Choice 6 ()

the field C will be showed only if the field A is 2 AND field B is 4

So to apply the patch just replace the two following files in the conditionnal field version 6.x-1.x-dev from 2009-Feb-02.

I left some french comments in the code in case it can help.

Hope this will help somebody!

Dany

Sonsored by :
Interconnect Telecommunucations
Batisseurs de Reseaux / Network Builders
http://www.interconnectinc.qc.ca/

dan_theman’s picture

StatusFileSize
new11.6 KB

it seems that my last post did not get the zip file correctly, here is again.

Dany

mitchell’s picture

StatusFileSize
new103.24 KB

Haven't tested this yet, but here's a patch of #8.

kaay’s picture

its not working

mitchell’s picture

Status: Patch (to be ported) » Needs work
peterpoe’s picture

This patches the whole file. I can't see what's changed. Can you reroll properly against latest dev? Thanks.

geraldito’s picture

Patch of #9 is not working for me but substituting conditional_fields.js and conditional_fields.module files with files from zip of #8 works fine and makes multiple controller fields working for me.

x_magnet_x’s picture

Hi,

I use Drupal 6 with CCK2 + Multigroup (and Services/AMFPHP) for a Flex based Page.
In my Flex Page I have a created a Block Component, because I need to combine Text, Images and Videos.
The Block Comnponent has nothing to do with the Block Module in Drupal!!!
The order of these Blocks is unsorted, so the User for example can produce a Text Block wich is followed by a Image Block or a Video Block and so on.

Example:
Text, Image, Video, Image, Text, Video...
or
Image, Text, Text, Video, Video, Image, Image, Text....

In Drupal I have a Content Type with a Multigroup which includes a Slecet Box (so the User can choose the Block Type (Text, Image, Movie)), a Text Field (FCK), a Image Upload Field (for Image Block), and a File Upload Field (for Movie Block).

The Multigroup is set to unlimited, so the User is able to add unlimted Blocks!
The combination with the Service Module and the multigroup works great, but the Usability is not as good, because all "Block" Types are always displaying. I need to hide the additional fields. So I found the Conditional Fields Modul, which is what I searched for! But it does not work. Is there a alternate Module which is working with Multigroups? Or a Multigroup Patch for the conditional Field?

Bilmar’s picture

subscribing

peterpoe’s picture

peterpoe’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Needs work » Fixed

Just committed on 2.x-dev branch a big patch that allows multiple controlling fields per controlled field. Please test!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mysterwii’s picture

Status: Closed (fixed) » Active

Hi,

Thanks for this great module but I have a problèm.

I would like select C controlled field if you choose a choice in A field OR B field.
C field is the final answer for the 2 choices.

A field
choice 1 ()
choise 2 () -->controlling value

B field
Choice 3 ()
Choice 4 () -->controlling value

C field (controlled field)
Choice 5 ()
Choice 6 ()

The field C will be showed only if the field A is 2 OR field B is 4.

Could you help me ?

Thanks

Mysterwii

lindsayo’s picture

I also need to use an OR operator.

askibinski’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

Bumping this to the 7.x dev-version.

I can see around line 370 in the .module file:

    // TODO: OR/XOR grouping of dependencies. 

Does anybody know if this is related to this feature?

peterpoe’s picture

Title: Multiple controller fields per single controlled field » Grouping dependencies by dependent with OR/XOR evaluation

#21: Right, this is a planned feature, coming (hopefully) soon.

drupov’s picture

subscribe

chris pergantis’s picture

subscribe

somanyfish’s picture

subscribe

bshensky’s picture

subscribe

Fidelix’s picture

Is this ever getting in?

Field conditional state from peem83 has this feature. Maybe borrow code from there?

ydnar79’s picture

This feature would be of GREAT benefit in many situations.... and from the age of this post and the other comments on here, it appears that I am not alone in this assessment.

So any word on adding this functionality?

Anyone have any success so far?

bryancasler’s picture

peterpoe can we can an update on this? What kind of work are we talking to get this support up and running.

bryancasler’s picture

There is another issue I'm interested in resolving that is dependent upon this issue being resolved first.

#1303862: Conditional fields has no effect on additional field collections

Over there I posted...

I'm placing a bounty of $100 to resolve this. Additionally, I'll match dollar for dollar the first $50 in pledges from other users.

If you're interested in tackling both issues, please take a look.

Rhodungeon’s picture

20 more dollars to the bounty! Field collection and Conditional fields should be fully functional and in the core!

bryancasler’s picture

What I'm trying to accomplish with Conditional Fields will most likely be solved by another model. For that reason I am removing this bounty.

Ref: #1067308: Integration with field_collection

LTech’s picture

I would like to show a field C if field A and/or field B and/or field C are filled.
Is this becoming an option with conditional fields? I'm not following the threads 100%. Please can you clarify.
Thanks

Frando’s picture

Status: Active » Needs review
StatusFileSize
new26.11 KB

The attached patch makes conditional_fields (D7) support OR and XOR conjunctions in addition to AND for multiple dependencies that point to the same dependent field.

For each dependency, under "Advanced dependency settings", you can select whether the dependency should belong to the AND, OR or XOR group. The default is AND, so nothing changes there. The three groups are ANDed togther, so you can easily create something like:
Show my_dependent_field if field_master_trigger is set to 1 and either field_condition_1 is set to 5 or field_condition_2 is set to 6, by selecting AND for the field_master_trigger dependee and OR for the two other dependees.

The patch works both on edit (states api) and view (server side evaluation) pages.

The patch also updates the states.js fork to the most recent version (which is also going to be included in Drupal 7.13). The conjunction groups weren't working properly with the older fork included in conditional_fields.

This patch is sponsored by Xarxa Media GmbH

bryancasler’s picture

This is fantastic Frando, can't wait to test it. I'm not sure if you've seen this, but another user posted a patch for Conditional Fields support two days ago. I don't know if either patch can benefit from one another, but I wanted to point it out. #1464950: Support for multiple "Field collection" and "Multifield" fields

bryancasler’s picture

Applying the patch against the latest git pull results in this when trying to patch "js/states.js"

patch unexpectedly ends in middle of line
Hunk #12 succeeded at 490 with fuzz 1.
klonos’s picture

If you're also using the latest 7.x-2.x-dev of jQuery Update, it could be #1448490: Remove the states.js overwrite as it was fixed upstream that was recently fixed or it could be #1239930: states.js appends span.form-required to every label of a dependent field for core, but I don't think it has a patch against D7 yet.

bryancasler’s picture

After enabling the module with the patch I'm getting...

Warning: include_once(C:\xampp\htdocs\playground10\sites\all\modules\conditional_fields\conditional_fields.module) [function.include-once]: failed to open stream: Permission denied in drupal_load() (line 1128 of 
C:\xampp\htdocs\playground10\includes\bootstrap.inc).

Warning: include_once() [function.include]: Failed opening 
'C:\xampp\htdocs\playground10/sites/all/modules/conditional_fields/conditional_fields.module' for inclusion (include_path='.;\xampp\php\PEAR') in drupal_load() (line 1128 of C:\xampp\htdocs\playground10\includes\bootstrap.inc).

Warning: include_once(C:\xampp\htdocs\playground10\sites\all\modules\conditional_fields\conditional_fields.module) [function.include-once]: failed to open stream: Permission denied in drupal_load() (line 1128 of 
C:\xampp\htdocs\playground10\includes\bootstrap.inc).

Warning: include_once() [function.include]: Failed opening 
'C:\xampp\htdocs\playground10/sites/all/modules/conditional_fields/conditional_fields.module' for inclusion (include_path='.;\xampp\php\PEAR') in drupal_load() (line 1128 of C:\xampp\htdocs\playground10\includes\bootstrap.inc).
Frando’s picture

@animelion:
Hm - that's strange, for me the patch both applies cleanly and I am not getting any Warnings. Maybe you checked out a wrong branch of conditional fields? The patch is for 7.x-3.x.

bryancasler’s picture

Thanks Frando, I had just pulled the most recent commit in git. I'll give this another go.

segana’s picture

Hi Frando!

Thanks for taking the time to create this patch as this is functionality I desperately need in conditional fields. I do have an issue however.

When I try to apply the patch, I get the following in Terminal (I use OSX).

patching file conditional_fields.module
can't find file to patch at input line 175
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/includes/conditional_fields.admin.inc b/includes/conditional_fields.admin.inc
|index 10ec07d..d3592b1 100644
|--- a/includes/conditional_fields.admin.inc
|+++ b/includes/conditional_fields.admin.inc
--------------------------
File to patch:

Any idea what I need to do to apply your patch?

Kind regards,

Matt

kimu’s picture

The patch includes changes to different files. As you see the prompt ask you to point which file you want to patch.
In that point of the procedure you have to write includes/conditional_fields.admin.inc.
It's enough to see the line which starts with |diff --git to see which file should be targeted.

segana’s picture

@kimu

You are a champion! thanks for the help. I'll go have a shot at that now :)

kimu’s picture

@Frando
thanks for sharing your work. Sadly, in my case this patch doesn't works and makes things worse.
As example:
I've 2 checkboxes, if the first is checked the second must be disabled. In the second is checked the first must be disabled. This mutual condition worked with the module, It stopped working applying the patch. These fields have only this condition, so there aren't interactions with other conditions.
I've seen other things stop working when the patch is applied. At the moment I don't have much time to go with massive tests, sorry for that, otherwise I would have provided more feedbacks.
Good effort anyway, probably it just needs further testing and small fixes to work correctly.

socialnicheguru’s picture

the patch doesn't apply at all using "git apply"
it applies but not cleanly using "patch -p1 <"

3rdLOF’s picture

Also fails in 4 out of 11 hunks againts the latest DEV version

Hunk #3 succeeded at 448 with fuzz 2 (offset 16 lines).
Hunk #4 succeeded at 549 (offset 4 lines).
Hunk #5 FAILED at 579.
Hunk #6 FAILED at 597.
Hunk #7 FAILED at 724.
Hunk #8 succeeded at 851 (offset 91 lines).
Hunk #9 succeeded at 910 with fuzz 2 (offset 91 lines).
Hunk #10 FAILED at 846.
Hunk #11 succeeded at 1136 (offset 110 lines).
4 out of 11 hunks FAILED -- saving rejects to file conditional_fields.module.rej
patching file includes/conditional_fields.admin.inc
patching file js/states.js
peterpoe’s picture

Status: Needs review » Fixed

Committed!

I updated the patch to current dev with some visual indicators added in the dependency overview tables to show the operator of grouped dependencies.

Many thumbs up and thanks to Frando for doing 99% of the work on this 4 years old issue.

If you find problems with the implementation, please don't reopen this issue, but file a new one.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pfhsmj0’s picture

--Deleted --

pfhsmj0’s picture

Issue summary: View changes

New issue description for Conditional Fields 3 (D7)