This is not the same as #735528: FAPI #states: Fix conditionals to allow OR and XOR constructions
Much simpler: A simple OR condition can be expressed as jQuery selector like this:
'#states' => array(
'visible' => array(
':input[name="checkboxes[foo]"], :input[name="checkboxes[bar]"]' => array('checked' => TRUE),
),
),
Translating:
- The selector matches more than one checkbox.
- The element should be visible when at least one of the checkboxes is checked.
- When no checkbox is checked, the element should not be visible.
Attached patch makes that work.
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | 1057748-19.patch | 711 bytes | rpayanm |
| #16 | drupal-1057748-16.patch | 1.14 KB | dmitriy.trt |
| #14 | trigger_state-1057748-d7-14.patch | 711 bytes | albert volkman |
| #14 | interdiff.txt | 993 bytes | albert volkman |
| #12 | trigger_state-1057748-d7-12.patch | 788 bytes | albert volkman |
Comments
Comment #1
dmitriy.trt commentedsubscribing
Comment #2
dmitriy.trt commentedIt works, thanks a lot! Patch makes it possible to depend on "checkboxes" element with simple condition like:
This means "element is invisible if all of checkboxes are unchecked".
Comment #3
rfayD8 first. Let's get these fixed on D8 and into D7.
Comment #4
sundrupal.states-checked.0.patch queued for re-testing.
Comment #5
james.williamssubscribe
Comment #6
geerlingguy commentedSub.
Comment #7
nagiek commentedPatch works for me, running Drupal 7.10. Handy!
Comment #8
nagiek commentedComment #9
sunRe-rolled against latest HEAD.
Comment #10
catchLooks fine, has had manual testing, shame we don't have qunit for stuff like this.
Committed/pushed to 8.x, back to 7.x for backport.
Comment #11
albert volkman commentedD7 backport.
Comment #12
albert volkman commentedbump (and updated patch to apply cleanly)
Comment #13
sunThis patch looks safe to backport for me, but I wonder whether the jQuery in D7 core supports .prop()?
(I guess it does, since I originally rolled this patch for D7, but I'm not 100% sure.)
Comment #14
albert volkman commentedGood point. Just checked this and D7 has jQuery 1.4.4-
http://drupalcode.org/project/drupal.git/blob/refs/heads/7.x:/misc/jquer...
and .prop() wasn't introduced until jQuery 1.6-
http://api.jquery.com/prop/
Perhaps we should use .is() instead?
Comment #15
sunPerhaps @nod_ can help out with those question.
Comment #16
dmitriy.trt commentedPatch #14 doesn't work because of missing colon before "checked" pseudo-class. Updated patch attached.
Comment #17
jason.fisher commented@16
Are you missing the check to see if it is checked? It seems like you are always returning the state of the first checkbox?
Comment #18
dmitriy.trt commented@jason.fisher,
Innermost function breaks the
jQuery.each()loop only if checked checkbox is found. Otherwise the loop will move to the next one. See jQuery API documentation:Comment #19
mgiffordNot surprising that the patch from 2 years ago needs a reroll.
Comment #20
rpayanmComment #21
mgiffordComment #22
mgifford@rpayanm reroll applies nicely in SimplyTest.me
What do we need to do to test this patch to mark it RTBC?