Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 CreditAttribution: Dmitriy.trt commentedsubscribing
Comment #2
Dmitriy.trt CreditAttribution: 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.williams CreditAttribution: james.williams commentedsubscribe
Comment #6
geerlingguy CreditAttribution: geerlingguy commentedSub.
Comment #7
nagiek CreditAttribution: nagiek commentedPatch works for me, running Drupal 7.10. Handy!
Comment #8
nagiek CreditAttribution: 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 CreditAttribution: Albert Volkman commentedD7 backport.
Comment #12
Albert Volkman CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: Dmitriy.trt commentedPatch #14 doesn't work because of missing colon before "checked" pseudo-class. Updated patch attached.
Comment #17
jason.fisher CreditAttribution: 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 CreditAttribution: 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?