dana ohayon
dana ohayon

Reputation: 61

submit button appears only after selection from the dropdown list doesn't work - drupal 7

Submit button appears after selecting from the select list drop down ,

Can anyone help me understand why it is not working?

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

Thanks dana

Upvotes: 0

Views: 195

Answers (1)

Muhammad Reda
Muhammad Reda

Reputation: 27053

Change the code to be

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

Change select[name="optinal_packages"] to be :select[name="optinal_packages"]. If it doesn't work, try to change the selector to be CSS-like #edit-optinal-packages.

Hence the code will be:

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

Upvotes: 0

Related Questions