Does anybody know how to change a multi-select nodereference drop-down to a single select using hook_form_alter? I have a nodereference field that I'm sharing across several content types. In most of the content types I need it to be a multi-select, but in one of them I need a single select. Here's what I'm doing now:

function example_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'test_node_form') {
    $form['field_projects']['#after_build'][] = 'example_noderef_single_select';
  }
}

function example_noderef_single_select($form_element, &$form_state) {
  $form_element['nid']['nid']['#multiple'] = FALSE;
  $form_element['nid']['nid']['#size'] = 1;
  
  return $form_element;
}

After doing this, the field does render as a single select, but it doesn't save the selected value after saving the node. Is there something else that needs to be done after altering the field.

Comments

LaurentAjdnik’s picture

Tagging