duanji9378 2012-03-20 20:09
浏览 30
已采纳

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

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),
  • 写回答

2条回答 默认 最新

  • dpjjr42626 2012-03-21 17:26
    关注

    Ok, I found the solution. Hopefully this will help someone in a similar situation to mine.

    ':input[name="account_type"]' => array('value' => 1),
    

    needed to be:

    ':input[name="account_type"]' => array('value' => "1"),
    

    Apparently, the javascript in IE was evaluating literal type/value not just value: 1 !== "1" etc. Once I fixed this it started working like a champ.

    also there was another instance in my code where the value was coming from a PHP variable, It wouldn't accept the variable as an int, but accepted it as a string...

    ':input[name="account_type"]' => array('value' => "$id"),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制