0

I have a view with a filter "Has taxonomy term", this filter is an exposed filter and is set to be a "Dropdown" and "Show Hierarchy"

The vocabulary has parents and children term (hierarchical).

The filter works fine but the html tags of the select dropdown are incorrect. The parent terms should be wrapped in instead of (see image 2)

Can I override this?

enter image description here

I trying to do it with hook_form_alter() but I see that the construction of the select itself is done by drupal_map_assoc() function. Then I see no way to do it? Can I put the value for '#options' in other way?

<?php
  $form['undergraduate']['school_country'] = array(
    '#type' => 'select',
    '#options' => drupal_map_assoc(array(t('UK'), t('Other'))),
    '#title' => t('In what country is your college or university located?'),
  );
?>
4
  • This is how it is meant to look/work. It does not provide <optgroup> functionality. I had to do this once and did it with custom code in a form_alter
    – 2pha
    Feb 7, 2013 at 13:29
  • ok, I just need that the user can't select a parent item, and indent to the right a little bit the children items. I will try to use form alter
    – chefnelone
    Feb 7, 2013 at 15:40
  • You could check if it is the top level (maybe by checking if it doesn't have a - at the start), and then add the attribute disabled (disabled="disabled")
    – 2pha
    Feb 8, 2013 at 8:56
  • You could also use this module: drupal.org/project/term_reference_tree. It has on option to only allow selection of the lowest term in the hierarchy. I used it on a site recently and it worked well.
    – 2pha
    Feb 8, 2013 at 8:57

1 Answer 1

1

You could check if it is the top level (maybe by checking if it doesn't have a - at the start), and then add the attribute disabled (disabled="disabled")

You could also use this module: drupal.org/project/term_reference_tree. It has on option to only allow selection of the lowest term in the hierarchy. I used it on a site recently and it worked well.

1
  • thanks, I didn't know the term_reference_tree module.
    – chefnelone
    Feb 11, 2013 at 7:41

Your Answer

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

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