Hey guys love the module. Could you please clear this up for me.

I am using hook_form_alter to add a default value to the reference field. It is showing in the array when i run

dpm($form);

See attached image

But the field remains with value - none -

My Code is as follows

function soul_form_alter(&$form, &$form_state, $form_id) {
	if($form_id == 'action_node_form') {
		$form['field_client']['und']['#default_value'] = array(1 => 'Test Client');
	}
}

I have also tried it as

function soul_form_alter(&$form, &$form_state, $form_id) {
	if($form_id == 'action_node_form') {
		$form['field_client']['und']['#default_value'] = array($clientid => $clientname); 
	}
}

I was just wondering if it is possible to set a default value or if the module overrides it some how. If so is there a way around this.

Thanks for taking the time to read this.
Gary

CommentFileSizeAuthor
devel-form.png24.37 KBghaddon

Comments

joachim’s picture

Are you sure that's to do with this module's work -- have you tried disabling it?

IIRC, FieldAPI does a lot of its widget building in an #after_build callback, so hook_form_alter() won't get to see everything.

ghaddon’s picture

It only wanted the entity id so this works

function soul_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == 'action_node_form') {
        $form['field_client']['und']['#default_value'] = $clientid;
    }
}
ghaddon’s picture

Status: Active » Closed (fixed)
brunorios1’s picture

Category: Support request » Bug report
Status: Closed (fixed) » Active

I´m having the same problem.

I have this scenario (fresh install):

Department (Vocabulary)

Category (Vocabulary)
- Department (Field - Term reference to Department Vocabulary)

Product (Node)
- Department (Field - Term reference to Department Vocabulary)
- Category (Field - Term reference to Category Vocabulary - Options limited according to matching Department field values)

I changed the default value of Department using a custom module:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'product_node_form') {
  	$form['field_department'][LANGUAGE_NONE]['#default_value'] = 1; // Department One
  }
}

But the Category field is not limited on the page load:
http://i.imgur.com/qnKcr1z.png

It only works if I select another value on the Department field and select Department One again:
http://i.imgur.com/jhoGfJi.png

Thank you.

--
EDIT:

Actually, it works. Sorry about that.

brunorios1’s picture

Status: Active » Closed (works as designed)
jomarocas’s picture

This is still wrong, i want to put the default value in category, but no working because depent of the department, i need to put default value in category with depent of department