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

问题描述 投票:0回答:1

从选择列表下拉列表中选择后出现提交按钮,

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

$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'),
        ),
    ),
);

谢谢达娜

drupal drupal-7 drupal-fapi
1个回答
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'),
© www.soinside.com 2019 - 2024. All rights reserved.