Drupal 7 Forms API条件逻辑无法在IE中运行

Fra*_*llo 2 php drupal drupal-7 drupal-forms drupal-modules

我有一个带有一堆字段的drupal 7表单:

$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),
    ),
  ),
);
Run Code Online (Sandbox Code Playgroud)

在Firefox/Chrome/Opera中,此表单的所有版本都应该正常运行.但是在IE的所有版本中,表单都使用display:none初始化; 无论account_type中的值是什么,所有条件字段上的样式.更改account_type的选定选项不会影响隐藏状态.

有关调试此表单的任何提示都很棒.

笔记:

  • 我不是Drupal开发人员,我继承了这个网站.只是试图解决最后几个错误,以便我们可以上线
  • 有比上面列出的更多的字段,我只是给了你一些适用的字段,以便你可以得到我的表单设置方式的要点
  • 开发中表单的当前网址:https://northeastcleanpower.com/enroll_new
  • 我正在使用http://www.browserstack.com/来调试IE 7 - 10pp4(我认为我们只需支持8及以上)

我也尝试过:

  • ':select[name="account_type"]' => array('value' => 1),
  • '#edit-account-type' => array('value' => 1),

Fra*_*llo 12

好的,我找到了解决方案.希望这可以帮助处于类似情况的人.

':input[name="account_type"]' => array('value' => 1),
Run Code Online (Sandbox Code Playgroud)

需要是:

':input[name="account_type"]' => array('value' => "1"),
Run Code Online (Sandbox Code Playgroud)

显然,IE中的javascript正在评估文字类型/值而不仅仅是值:1 !== "1"等.一旦我修复了它,它开始像冠军一样工作.

我的代码中还有另一个实例,其中值来自PHP变量,它不接受变量作为int,但接受它作为字符串...

':input[name="account_type"]' => array('value' => "$id"),
Run Code Online (Sandbox Code Playgroud)