3

So I have this view with exposed filter of taxonomy terms with depth, I had selected some of the terms to limit the selection.

everything works just fine but the issue is that the default value of the exposed filter (combo-box) is set to the latest entry (taxonomy term), and I want to set it to that -All- thing.

I know that if I don't select any of the terms to limit the selection, it'll be set on -All- as default value for the exposed filter, but I don't wanna do that!

the question seems quite simple but I couldn't figure this out! thanks.

1 Answer 1

2

in template.php:

function MY_THEME_form_views_exposed_form_alter(&$form, &$form_state) {
  // dpm($form);
  if ($form['#id'] == 'MY_EXPOSED_FORM_ID') {
    // Modifications go here.
    // example: (change the field name to yours)
    // $form['field_adv_cat_1_tid']['#default_value'] = 'All';
  }
}

then clear the cache.

19
  • Thanks xurshid for answer but the thing is I rather to fix it via views itself, if it's not possible I try template.php thing, btw I tried your approach and couldn't make it work, maybe I did sth wrong there, should I replace the ID of my select field in $form['field_adv_cat_1_tid']['#default_value'] = 'All'; instead of field_adv_cat_1_tid ?
    – Sohail
    Commented Dec 25, 2013 at 11:25
  • 2
    @Sohail 1. This function is a hook_form_FORM_ID_alter() function. You can read about it by this link: api.drupal.org/api/drupal/modules!system!system.api.php/…. 2. open template.php file and paste above code into it, and change MY_THEME to your theme name. Clear cache and use dpm($form) to find the id of your form. Then change MY_EXPOSED_FORM_ID to your form's id.
    – xurshid29
    Commented Dec 25, 2013 at 11:31
  • @Sohail here is a nice tutorial (unfortunately in russian) - xandeadx.ru/blog/drupal/304, shows how to work with Devel
    – xurshid29
    Commented Dec 25, 2013 at 11:41
  • 1
    @Sohail, By default, Drupal replace underscore (_) in form id of the form into dash(-) when render HTML of the form. You should use views_exposed_form_resellers_page or check with dpm() function or print_r or var_dump. Commented Dec 25, 2013 at 12:37
  • 1
    @xurshid29, I have checked views_exposed_form and found that #id attribute of form and #form_id is different. I think, as all exposed form has same form id (views_exposed_form), so views module is setting different #id attribute of the form for each different form. In drupal_prepare_form() in form.inc, then if #id attribute is not set, its converting form_id and setting to #id attribute of form. Commented Dec 26, 2013 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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