If the the hierarchical select dropdown is set to 'enforce deepest', on selecting the top dropdown category, the other dropdowns will appear automatically with default values. However if you don't hit 'add' and the term is not added to the dropbox, the term is still saved for the node when the form is submitted.

The select dropdown is set dynamically using the form_alter hook like so:

$form['taxonomy'][20]['#title'] = t('Business listing categories');
$form['taxonomy'][20]['#description'] = t('You must select at least one category.');
$form['taxonomy'][20]['#required'] = 1;
$form['taxonomy'][20]['#weight'] = 5;
$form['taxonomy'][20]['#type'] = 'hierarchical_select';
$form['taxonomy'][20]['#hierarchical_select_settings'] = array(
'module' => 'taxonomy',
'save_lineage' => FALSE,
'enforce_deepest' => TRUE,
'params' => array(
'vid' => 20,
),
'animation_delay' => 400,
'dropbox_title' => t('These are the terms you selected'). ':',
'dropbox_limit' => 3,
);

Is this a bug? Is there anyway around this?

Thanks for any help :)

Comments

wim leers’s picture

Title: Enforce deepest save a term even when not added » enforce_deepest + multiple_select + default_value: term saved even when not added to dropbox
Version: 5.x-2.0 » 5.x-2.x-dev
Component: Code - Taxonomy » Code
Category: bug » task
Status: Active » Postponed

I'm afraid this is currently by design…

By setting #default_value, FAPI will consider this value the selected item(s). So in se it's not a bug. What you would need however, is the ability to set the start value (this is the differentiation in terminology I suggest) of the hierarchical select.

I will implement this either in a next 2.x release, or in the 3.0 release. This is low-priority to me. A patch is of course welcome.

Good catch though, I had never noticed this awkwardness. Thanks!

Kat_Sweden’s picture

Title: enforce_deepest + multiple_select + default_value: term saved even when not added to dropbox » Enforce deepest save a term even when not added
Version: 5.x-2.x-dev » 5.x-2.0
Component: Code » Code - Taxonomy
Category: task » bug
Status: Postponed » Active

On further testing, it doesn't matter if 'enforce deepest' is true or false, the term is still saved whether or not it is added to the dropbox.

Kat_Sweden’s picture

Thanks for letting me know. I'll see if I can get a patch together.

wim leers’s picture

Title: Enforce deepest save a term even when not added » enforce_deepest + multiple_select + default_value: term saved even when not added to dropbox
Version: 5.x-2.0 » 5.x-2.x-dev
Component: Code - Taxonomy » Code
Category: bug » task

Excellent. :)

Putting back the proper states.

wim leers’s picture

How's that patch coming along? If you haven't had the chance yet to start it, please let me know.

wim leers’s picture

Title: enforce_deepest + multiple_select + default_value: term saved even when not added to dropbox » Ability to set start value of the hierarchical select
Category: task » feature
wim leers’s picture

Status: Active » Closed (won't fix)

While thinking about how to implement this, I actually think now that it's *bad* to set a start value for the hierarchical select when the dropbox is empty. The start value should always be the level label or <none>.

beauz’s picture

How would I go about setting the default value on a heirarchical select field using a value from the querystring... what file would i be looking to edit?