Closed (fixed)
Project:
Hierarchical Select
Version:
7.x-3.0-alpha5
Component:
HS API implementation questions
Priority:
Normal
Category:
Support request
Assigned:
Reporter:
Created:
5 Mar 2012 at 13:33 UTC
Updated:
29 Nov 2017 at 15:11 UTC
Jump to comment: Most recent
Comments
Comment #1
sokrplare commentedClosing this out since it's been a while, but in case others stumble across take a peek at the API.txt file which shows a FAPI form element example for HS.
Hard to tell out of context, but I'm guessing you want something closer to:
$form["field_location"]['#default_value']=$location;, but not certain.Comment #2
druderman commentedI can confirm that you cannot set the default using the proscribed method using FAPI if the HS field widget is set to "Save term lineage". If it's set to "Save only the deepest term", then it works.
function MYMODULE_form_alter(&$form, &$form_state, $form_id)
{
$form['field_things']['und']['#default_value'] = '3';
}
Is this a bug?
Ideally, I'd like to give my form, which has a Taxonomy HS field, a parameter so it will preselect and expand one term i.e /myform?tid=3 .
Comment #3
wim leersIf term 3 is a root-level term, then it will work just fine when "Save term lineage" is enabled. If it is not a root-level term, but e.g. a term in the 3rd level, then … you of course need to provide the full lineage ;) For example:
array(34, 746, 3).Comment #5
TravisJohnston commentedInstead of opening another issue for the same reason, I'll just add to this one.
I am trying to set the default value after I grab information for the user filling out the form. I've tried a number of ways with no luck.
I've tired the following:
using an array
using the syntax shown in the API.txt file
and a single ID set
This is being down after a rebuild is sent due to the form being filled out with default values after the user makes a specific selection from a list above. I included this before hand to remove any old state data: