$(document).bind('state:visible', function(e) {
    if (e.trigger) {
      $(e.target).closest('.form-item, .form-wrapper')[e.value ? 'show' : 'hide']();
    }
  });

Fieldsets have by default:

  1. no IDs
  2. 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).

CommentFileSizeAuthor
#2 drupal.states-types.2.patch2.55 KBsun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

casey’s picture

You can set IDs:

function form_process_fieldset(&$element, &$form_state) {
  ...
  $element['#attributes']['id'] = $element['#id'];
sun’s picture

Title: Javascript States cannot hide fieldsets » Javascript #states cannot hide fieldsets, radios, checkboxes
Status: Active » Needs review
FileSize
2.55 KB

Same applies to radios and checkboxes.

I hope that attached patch fixes all 3 in 1 shot. At least, I can confirm radios.

rburgundy’s picture

Hello,

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

andrewmacpherson’s picture

Issue tags: +FAPI #states

tagging

sun’s picture

What's wrong with this patch? RTBC, anyone?

sun’s picture

Assigned: Unassigned » sun
moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

this 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.

marcingy’s picture

I can confirm this works for checkboxes as well.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

marcingy’s picture

Status: Fixed » Reviewed & tested by the community

Just did a CSV up and this doesn't appear to have been committed and no commit exists in the logs for it either.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)
Issue tags: -FAPI #states

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

mattew’s picture

Issue summary: View changes

Sorry, 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