-1

I have created a module to alter a select dropdown of a view's exposed filter like this

function myform_form_alter(&$form, &$form_state, $form_id) { 

   if ($form_id == "views_exposed_form" && $form['#id'] == "views-exposed-form-staff-page") {
$form['field_department_tid']['#type'] = "select";
    $form['field_department_tid']['#size'] = null;
    $form['field_department_tid']['#default_value'] = $form['field_department_tid']['#options']['All'];
    $form['field_department_tid']['#options'] = array(
      'All' => t('All Offices'),
      '6' => t("Office of the Chairman"),

'Administration & Financial Affairs Department' => array(
            '2'=> t('Administration'),
            '3' => t('Finance'),
            '4' => t('HR'),

         ),



    );
 }

But occasionally it is showing the original unaltered select list instead of the new select list and in such cases, I need to clear cache every time to display the changed dropdown.

What is the problem with my code?

0

Try this way

Change

$form['field_department_tid']['#default_value'] = $form['field_department_tid']['#options']['All'];

to

$form['field_department_tid']['#default_value'] = t('All Offices');

| improve this answer | |
  • It is not a sing value that is not showing, but entire set – user7282 May 24 '17 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.