2

I want to make a taxonomy field widget that allows me to select the maximum level depth of the taxonomy vocabulary. This widget should be used in node forms and the value (selected term) should be saved in the node object.

What is the best (Drupal) way to approach this?

I don't want to use hierarchal select.

  • Can you explain a bit more what your problem is. Don't you know how to create a widget, or is there something specific in the widget you are creating that is giving you trouble? – googletorp Jan 10 '12 at 8:37
  • I have a taxonomy vocabulary with 3 levels/depths. In my node form I want to add a widget which allows the user to only select a term our of the first 2 levels of my vocabulary. (so the third level should can't be chosen). – Filip Heymans Jan 10 '12 at 14:04
1

Content Taxonomy is what you're looking for. It extends the default select list widget and adds a maximum level depth.

1

For me not works any module to remove unnecesary taxonomy depths, but I can fix it with my own code like this:

function _remove_sub_services(&$form, &$form_state) {

foreach ($form['profile_fields']['field_select_the_service'][LANGUAGE_NONE]['#options'] as $index => $value){

    if(strstr($value, '--')){
        unset($form['profile_fields']['field_select_the_services'][LANGUAGE_NONE]['#options'][$index]);
    }
}


return $form;

}

// I call this code inside a hook_form_alter

0

There is a new module called Client-side hierarchical (https://www.drupal.org/project/cshs) that does a good UI and solves it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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