Multiple controller fields per single controlled field
| Project: | Conditional Fields |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
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?

#1
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.
#2
#3
subscribe
#4
subscribe
#5
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.
#6
#7
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/
#8
it seems that my last post did not get the zip file correctly, here is again.
Dany
#9
Haven't tested this yet, but here's a patch of #8.
#10
its not working
#11
#12
This patches the whole file. I can't see what's changed. Can you reroll properly against latest dev? Thanks.
#13
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.