Form API #states with #default_value? I have a form which has a select with a #default_value which get's set when the user has errors/has filled out the form. Then I have two fields with a #states that show them when the select has a value.

So basically

$checkout_form['wrap'] = array(
  '#type' =&gt; 'select',
  '#title' =&gt; t('How many item(s) do you wish to have wrapped?'),
  '#default_value' =&gt; $default_giftwrap_amount,
);


Then I have a fieldset and a textarea with

  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="wrapping[wrap]"]' =&gt; array('!value' =&gt; ''),
    ),
  ),


which make those two fields show when ever something is selected.

But my problem is when the #default_value is say 400 (ie something is selected) it doesn't show the fieldset and textarea, only when you select something.

Is there anyway for it to check on page load as well as onchange?
Your default value in the select element must be the array key of your values not the value it self.So i set an empty "value" and check for that.

That said i got this working like:

$form['wrap'] = array(
  '#type' =&gt; 'select',
  '#title' =&gt; t('How many item(s) do you wish to have wrapped?'),
  '#options' =&gt; array('--', '1', '2', '300', '400'),
  '#default_value' =&gt; 2,
);
$form['textarea'] = array(
  '#type' =&gt; 'textarea',
  '#title' =&gt; t('How many item(s) do you wish to have wrapped?'),
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="wrap"]' =&gt; array('!value' =&gt; 0 ),
      ),
    ),
  );


In the example above my default value is 300.
The state visibility will work onload and onchange and will show the textarea only when the value is the empty value (0 => '--')