Drupal 7 Forms API Conditional Logic not working in IE
Posted
by
Francis Yaconiello
on Stack Overflow
See other posts from Stack Overflow
or by Francis Yaconiello
Published on 2012-03-20T20:09:13Z
Indexed on
2012/03/21
17:29 UTC
Read the original article
Hit count: 255
I have a drupal 7 form with a bunch of fields:
$form['account_type'] = array(
'#title' => t('Utility Account Type'),
'#type' => 'select',
'#options' => necp_enrollment_administration_portal_account_type_options(),
'#required' => TRUE,
'#default_value' => isset($form_state['values']['account_type']) ? $form_state['values']['account_type'] : '',
);
// Should show if account_type = 1
$form['home_wrapper'] = array(
'#type' => 'fieldset',
'#states' => array(
'visible' => array(
':input[name="account_type"]' => array('value' => 1),
),
),
);
$form['home_wrapper']['first_name_1'] = array(
'#title' => t('Primary Account First Name'),
'#type' => 'textfield',
'#default_value' => isset($form_state['values']['first_name_1']) ? $form_state['values']['first_name_1'] : '',
'#states' => array(
'required' => array(
':input[name="account_type"]' => array('value' => 1),
),
),
);
$form['home_wrapper']['last_name_1'] = array(
'#title' => t('Primary Account Last Name'),
'#type' => 'textfield',
'#default_value' => isset($form_state['values']['last_name_1']) ? $form_state['values']['last_name_1'] : '',
'#states' => array(
'required' => array(
':input[name="account_type"]' => array('value' => 1),
),
),
);
// Should show if account_type = 2
$form['business_wrapper'] = array(
'#type' => 'fieldset',
'#states' => array(
'visible' => array(
':input[name="account_type"]' => array('value' => 2),
),
),
);
$form['business_wrapper']['company_name'] = array(
'#title' => t('Company/Organization'),
'#type' => 'textfield',
'#default_value' => isset($form_state['values']['company_name']) ? $form_state['values']['company_name'] : '',
'#states' => array(
'required' => array(
':input[name="account_type"]' => array('value' => 2),
),
),
);
In Firefox/Chrome/Opera all versions this form behaves as it should. However in all versions of IE the form initializes with display:none; style on all of the conditional fields regardless of what the value in account_type is. Changing the selected option of account_type does not effect the hidden status.
Any tips on debugging this form would be awesome.
Notes:
- I am not much of a Drupal developer, I inherited this site. Just trying to iron out the last couple bugs so we can go live
- there are more fields than are listed above, I just gave you some of the applicable ones so that you could get the gist of how my forms were setup
- current url for the form in development: https://northeastcleanpower.com/enroll_new
- I'm using http://www.browserstack.com/ to debug IE 7 - 10pp4 (I think we only have to support 8 and up though)
I've also tried:
':select[name="account_type"]' => array('value' => 1),
'#edit-account-type' => array('value' => 1),
© Stack Overflow or respective owner