I was hoping that this would functionality would be in the D7 version of node reference just like in D6, are there any plans for this?

Comments

Status:Active» Postponed

No plan for any new feature in D7 until we have a stable 1.0 version equivalent with the D6 versions. Only then can we afford to consider new features, if none of the "designed for D7" moduels like Relation comes out.

In the meantime, is there any way I could populate the field with a default through a hook_form_alter()?

For example, would it be possible to set a #default_value for the node reference field (or a user reference, for that matter), somehow?:

<?php
/**
* Implements hook_form_FORM_ID_alter().
*/
function custom_form_page_node_form_alter(&$form, $form_state, $form_id) {
 
// If there's a node reference id in the URL, add the list reference automatically.
 
if (arg(3)) {
   
$nid_to_reference = arg(3);
   
$form['field_node_reference']['#default_value'] = arg(3); // It'd be nice if something like this worked...
 
}
}
?>

Edit: I also tried building the reference with an autocomplete text field, but that didn't work:

<?php
  $node
= node_load(arg(3));
 
$list_reference = $node->title . ' [nid:' . $node->nid . ']';
?>

Update: I had to set the #default_value in the following way:

<?php
  $form
['field_note_list_reference']['und'][0]['nid']['#default_value'] = arg(3);
?>

It was helpful for me to look at the structure of node_reference_autocomplete_value() in node_reference.module.

Would love to see this implemented some day!

I also require this feature and will be using hook form alter in the meantime.

geerlingguy, thank you!

Working prepopulate node reference fileld with node clone module:

<?php
   
if ((arg(2) == 'clone') && !(isset($form['field_original']['und'][0]['nid']['#default_value'])) ) {
     
$form['field_original']['und'][0]['nid']['#default_value'] = arg(1);
    }
?>

i would need that too- in d6 when only ONE value was available for the dropdown this one was selected by default- right now there is an "- Select a value -" option selected as default :(