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
Comment #1
wim leersI'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!
Comment #2
Kat_Sweden commentedOn 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.
Comment #3
Kat_Sweden commentedThanks for letting me know. I'll see if I can get a patch together.
Comment #4
wim leersExcellent. :)
Putting back the proper states.
Comment #5
wim leersHow's that patch coming along? If you haven't had the chance yet to start it, please let me know.
Comment #6
wim leersAlso see http://drupal.org/node/226067#comment-799845.
Comment #7
wim leersWhile 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>.Comment #8
beauz commentedHow 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?