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.
$(document).bind('state:visible', function(e) {
if (e.trigger) {
$(e.target).closest('.form-item, .form-wrapper')[e.value ? 'show' : 'hide']();
}
});
Fieldsets have by default:
- no IDs
- no "form-item" or "form-wrapper" classes
(1) can be solved easily (and I think we should fix that), but I'm not sure what is the way forward for (2).
Comment | File | Size | Author |
---|---|---|---|
#2 | drupal.states-types.2.patch | 2.55 KB | sun |
Comments
Comment #1
casey CreditAttribution: casey commentedYou can set IDs:
Comment #2
sunSame applies to radios and checkboxes.
I hope that attached patch fixes all 3 in 1 shot. At least, I can confirm radios.
Comment #3
rburgundy CreditAttribution: rburgundy commentedHello,
I was wondering if the new FAPI: JavaScript States system will allow:
1) hiding a field depending on the value of field a AND field b
2) hiding a field depending on the value of field a OR field b
Thank you
Comment #4
andrewmacpherson CreditAttribution: andrewmacpherson commentedtagging
Comment #5
sunWhat's wrong with this patch? RTBC, anyone?
Comment #6
sunComment #7
moshe weitzman CreditAttribution: moshe weitzman commentedthis fills a pretty big hole in form element theming. now supports custom attributes and ids. important for skinr as well. Code looks proper and straightforward.
Comment #8
marcingy CreditAttribution: marcingy commentedI can confirm this works for checkboxes as well.
Comment #9
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #10
marcingy CreditAttribution: marcingy commentedJust did a CSV up and this doesn't appear to have been committed and no commit exists in the logs for it either.
Comment #11
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #14
mattew CreditAttribution: mattew commentedSorry, maybe I misunderstood, but I encountered the same issue, trying to hide a fieldset (collapsible = TRUE, collapsed = FALSE) with a checkbox, and I found the solution: The fieldset have to explicitly provide an #id attribute.
Maybe this should be pointed out in the documentation?
Thanks