4

I have found the theme template for exposed filter form of view. Template name: views-exposed-form.tpl.php

Inside the template I found the $widgets array and for loop for each $widget display in form.

But it is rendered HTML widget How can I get only values array for each combo box to render output for my combo box as I want?

for instance:

I have one combo called Country: Country has hierarchy level of list

Asia
- India
- Sri lanka
- thailand
- Indonesia

etc...

So, I would like to make my combo just like this

http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_optgroup

<select>
  <optgroup label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
  </optgroup>
  <optgroup label="German Cars">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
</select>

This will identify the parent / child category in combo? can we do this directly in drupal 7 Views for Expoesd Filters Combo ? or How can I theme myself to override its HTML?

3 Answers 3

1

You can try to catch it with hook_form_alter(): $form_id is views_exposed_form, and $form contains all the values.

$form['field_custom']['#options'] = array(
  'group1' => array('key11' => 'value11', 'key12' => 'value12'),
  'group2' => array('key21' => 'value21', 'key22' => 'value22' ),
);
9
  • I have check with $form_id == "views_exposed_form"; after that I want to replace the value of Select Options array to Group Select Options but will not replace How Can I replace the value of Select Options in theme_form_alter method
    – AshwinP
    Commented Sep 26, 2013 at 8:59
  • The hook_form_alter() is in custom module not in the theme. You can also use devel module and dpm() function to display what the $form variable contains. You can alter the values with : $form['field_custom']['#options']
    – pico34
    Commented Sep 26, 2013 at 9:21
  • What is the structure of ARRAY I can pass to $form['field_custom']['#options']
    – AshwinP
    Commented Sep 26, 2013 at 9:25
  • 1
    Display the original struture with using devel module and dpm function, you'll see how is the actual structure ot the array. For a select list with groups, look at the updated answer above
    – pico34
    Commented Sep 26, 2013 at 9:33
  • Hey, @pico34 it is working but there is one problem to identify the parent child option. I have do this in custom module if($form_id == "views_exposed_form") { print_r( $form['field_geography_countries_tid']['#options'] ); } > This will return an array single dimension so, How can I check that which options are parent/child
    – AshwinP
    Commented Sep 26, 2013 at 10:58
0

Maybe Views exposed form layout module may help you.

0

You can control everything at different levels, with the "views-exposed-form" template, and editing the widgets' HTML code in the "theme_preprocess_views_exposed_form".

I wrote a post on how to do this in my blog: http://danyalejandro.com/portafolio/content/theming-exposed-filters-drupal-7-views

Theming exposed filters in Drupal 7 Views (Web Archive Retrieved)

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.