Is it possible to change fieldset title if collapsed with #states I'm trying to use #states in form api to change the title of a fieldset based on his collapsed states.

so far here's my code : 

$form['advanced'] = array(
  '#type' =&gt; 'fieldset',
  '#title' =&gt; t('Advanced search'),
  '#collapsible' =&gt; TRUE,
  '#collapsed' =&gt; TRUE,
  '#attributes' =&gt; array('class' =&gt; array('search-advanced', 'clearfix')),
  '#states' =&gt; array(
    '#title' =&gt; array(
      array('fieldset#edit-advanced' =&gt; array('#collapsed' =&gt; 'Hide advanced search')),
    ),
  ),
);


I've tried different things, but without success.

Thanks a lot.
It is true that there were some issues with #states and fieldsets, such as #states can't hide/show fieldsets, but in your case the code doesn't work because #title is not an handled state, and #collapsed is not a handled state for the remote condition.

The list of the implemented states is given in drupal_process_states():


enabled
disabled
required
optional
visible
invisible
checked
unchecked
expanded
collapsed


The states used for the remote conditions are the following:


empty
filled
checked
unchecked
expanded
collapsed
value


It would also be hard to implement that, as the state needs to be boolean, and the remove condition says the value of the state for the other form field.

For example, if foo is a select list, the state for a form field could be the following one.

'#states' =&gt; array(
  // Show the settings if 'bar' has been selected for 'foo'.
  'visible' =&gt; array(
    ':input[name="foo"]' =&gt; array('value' =&gt; 'bar'),
  ),
),


This state would make the form field visible when the value selected from the list is bar.