只有从下拉列表中选择后才能显示提交按钮 - drupal 7

时间:2013-02-03 12:08:14

标签: drupal drupal-7 drupal-fapi

从选择列表下拉菜单

中选择后,将显示

提交按钮

任何人都可以帮助我理解它为什么不起作用吗?

$form['user_fields']['optinal_packages'] =  array(
    '#type' => 'select',
    '#title' => t('Optional Packages'),
    '#options' => $packages_array,  
    //'#weight' => 15,
    '#description' => t('Please press the "Push" button to update device package.'),    
    '#default_value' =>  -1,
   );



$form['user_fields']['push'] = array(
    '#type' => 'submit',
    '#value' => t('Push'),
    // '#weight' => 16,
    '#prefix' => '<div id="phone_user_push_package">',
    '#suffix' => '</div>',
    '#states' => array(
        'visible' => array(     // Action to take: Make visible.
        //':input[name="optinal_packages"]' => array('!value' => '-1'),
        'select[name="optinal_packages"]' => array('!value' => '-1'),
        ),
    ),
);

由于 布施

1 个答案:

答案 0 :(得分:0)

将代码更改为

$form['user_fields']['push'] = array(
    '#type' => 'submit',
    '#value' => t('Push'),
    // '#weight' => 16,
    '#prefix' => '<div id="phone_user_push_package">',
    '#suffix' => '</div>',
    '#states' => array(
        'invisible' => array( // edited line
            ':select[name="optinal_packages"]' => array('value' => '-1'), // edited line
        ),
    ),
);

select[name="optinal_packages"]更改为:select[name="optinal_packages"]。如果它不起作用,请尝试将选择器更改为类似CSS的#edit-optinal-packages

因此代码将是:

'#edit-optinal-packages' => array('value' => '-1'),