When using type "text_format", it generates a textarea and the filter form fieldset.
But in html, fieldset element is out of the div .form-item.
When you add #states on this element, it apply only to .form-item and not on fieldset.

One solution could be to add parents jquery function on states.js to the text-format-wrapper ?, sample line 372:

$(e.target).parents('.text-format-wrapper')[e.value ? 'show' : 'hide']();

But i'm not sure it's a good way...

An other solution could be to change the way the text_format is render to add filter form fieldset in the div.form-item ?

Or perhaps you can consider it's not a bug and text_format need to be in a container or a fieldest to get states working.

Regards
Mog.

Files: 
CommentFileSizeAuthor
#2 Screen shot 2011-05-30 at 11.12.47 AM.png118.72 KBcpliakas

Comments

ben kuper’s picture

Version: 7.0-rc2 » 7.0

The final version of D7.0 didn't took care of this... as for few other things considering the #states functionnality (#735528: FAPI #states: Fix conditionals to allow OR and XOR constructions is a very cool fix i think).

Anyway, this function changed a bit since the rc2 and the closest() function is used now, so i went along with your idea of changing the states.js, but in the final version of it.
I changed the parents() function a contionnal with hasClass() verification since parents() or parent() doesn't return the current element if nothing was found.

Line 481 :

      var elem = $(e.target).closest('.form-item, .form-submit, .form-wrapper');
	  if(elem.parent().hasClass('text-format-wrapper')){
		  elem = elem.parent();
	  }
	  elem[e.value ? 'show' : 'hide']();

I still think that it's not the good way to fix it as it's not really a states.js misfunctionning but as you said the text_format/text-area form fields generation that should be adjusted. At least i see it that way.

cpliakas’s picture

Version: 7.0 » 7.x-dev
FileSize
118.72 KB

This bug is still present in 7.2 release and the 7.x-1.x branch. Attaching a screenshot to further illustrate the bug.

PatchRanger’s picture

Confirmed : the bug is still alive in 7.15 release.

nod_’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +JavaScript

Happens in D8 as well.

Shiraz Dindar’s picture

Confirming this bug exists in 7.16.

haggins’s picture

Issue summary: View changes

I worked around the following way (could possibly be the general fix):

Copy the filter_process_format() function to your module and rename it to mymodule_filter_process_format().

Change the new function like this (adding 3 lines of code):

// snip

// Setup child container for the text format widget.
  $element['format'] = array(
    '#type' => 'fieldset',
    '#attributes' => array('class' => array('filter-wrapper')),
  );

  // The #states-bug fix:
  if (isset($element['value']['#states'])) {
    $element['format']['#states'] = $element['value']['#states'];
  }

  // Prepare text format guidelines.
  $element['format']['guidelines'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('filter-guidelines')),
    '#weight' => 20,
  );

// snap

Finally, set the #process attribute of your text_format element to array('mymodule_filter_process_format').

amar.deokar’s picture

Simple work around !

 $form['container'] = array(
   '#type' => 'container',
   '#states' => array('visible' => array(':input[name="xyz"]' => array('value' => true),),),
 );

 $form['container']['mytext'] = array(
   '#type' => 'text_format',
   '#format' => 'full_html',
   '#title' => t('My text format'),
   //'#states' => array('visible' => array(':input[name="xyz"]' => array('value' => 'true'),),),
   );

I achieved #states results for my "mytext" field by putting "mytext" field inside "container" field and applying #states to "container" field rather than "mytext".

amar.deokar’s picture

Ideally by considering above(#7) work around we can update some basics designing in filter module.
Istead of wrapping text_format field in simple div we should have container field as parent field.
and attributes like #states should be applied to it. I am not sure about pros and cons of adding parent container to text_format field internally.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

chgasparoto’s picture

#7 worked perfectly here (D7). Thanks!

NancyDru’s picture

While #7 works just fine, IMHO it's clunky and not very Drupal-y.