0

I'm trying to create a Drupal web for a travel agency and need your help.

  • I store locations in a taxonomy with hierarchy, the structure looks like this:

    • Europe
      • France
        • Paris
      • Germany
        • Berlin
  • I'm using a view with "Has taxonomy terms (with depth)" filter, exposed as a selectbox.

  • "Show hierarchy in dropdown" is enabled

It works fine, but the selectbox starts to get pretty huge as the number of the location is increasing.

So my question is: Is it possible to show just the 1st and 2nd level of the taxonomy in the select box? Or is it possible to show each level of the taxonomy in a separate select box?

Thank you!

  • You don't mention which version of drupal, which makes a big difference. I had to do this in Drupal 7 recently and had to create my own module which supplied a block and used the form api to create the 3 separate hierarchical select boxes. The first 2 had the #ajax set so they would update the form and populate the next select. – 2pha Jan 25 '13 at 13:21
  • I use Drupal 7. I'm sure that custom module could solve this problem, but I'm trying to find some simple solution. – Marian Kmet Jan 31 '13 at 13:26
  • "Is it possible to show just the 1st and 2nd level of the taxonomy in the select box?" It is possible but I have never seen a module to do this. It could be done in a simple HOOK_form_alter. "Is it possible to show each level of the taxonomy in a separate select box?" The only module I have seen for this is Hierarchical Select. http://drupal.org/project/hierarchical_select. I have never used it though. I needed to implement this a few weeks back and implemented my own. – 2pha Feb 02 '13 at 14:07

3 Answers3

0

You should check this link. I am pretty sure, you will be able to it by some custom coding in any custom module or template.php

You can check this module too, really helpful.

Thanks

RajeevK
  • 418
  • 4
  • 14
0

"is it possible to show each level of the taxonomy in a separate select box?" The only module I have seen that might be useful to you is the Hierarchical Select module. http://drupal.org/project/hierarchical_select

2pha
  • 9,798
  • 2
  • 29
  • 43
0

Use hierarchical select module to create select list. This will give you a hierarchy with '-' symbol in front all child elements. Then you can alter the form with hook_form_alter function.

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
 if (($form_id == 'your_form_id')) {
  foreach ($form['tid']['#options'] as $term_key => $term) {
      // Check if this is a child by looking for '-' as first char in string
      $term_value = reset($term->option);
      if($term_value[0] == '-') {
        unset($form['tid']['#options'][$term_key]);
      }
    }
  }
}
Rohith Pv
  • 41
  • 3