0

Now and then I will come across a Drupal site that shows taxonomy terms to be selected in a drop down list. Example:

Fruit
    apple
    pear
Meat
    pork
    beef
..etc

And, while the child of each parent is selectable, the parent is not. How is this achieved, and how can I apply it to my taxonomy vocabulary who terms are 1 child deep?

3 Answers 3

1

Download and install this module http://drupal.org/project/term_reference_tree and check the Leaves only(Don't allow the user to select items that have children) option under manage fields-> click edit on taxonomy field.

It will select only the children not parent.

1

@Bala has a great answer for the node edit form, but it doesn't help with views filters or other front end displays. For views filters try https://drupal.org/project/better_exposed_filters combined with the code I gave for another question. This allows your view to limit the selection of parents on the filter and is also keyboard accessible.

I will be working on a node hierarchical DISPLAY today and when completed I will post it as a comment on my answer that I linked above.

1
0

Use the Simple Hierarchical Select module.

From the project page:

  1. Create a new field (type "Term reference") and select "Simple hierarchical select" as widget type.
  2. In the field settings, check the box Force selection of deepest level. This forces users to select terms from the deepest level, the leaf nodes in the tree.

The code looks cleaner than Client-side hierarchical select, which is another option. Both modules are available for use in Drupal 8 and 9. I don't recommend the original module, Hierarchical Select because there's no upgrade path beyond Drupal 7.

Thanks to @mparker17 for help on this one.

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.