I am using the References module for my content types. There are two content types: A and B. Nodes of one type have a reference to nodes of the other type.

I have a node titled ABC and I want to refer it in another node; the autocomplete in the reference field returns me ABC[nid:5] while I want just to have ABC.

How can I resolve this in simple way? Do I need another module?

Note there are nodes with the same title.

The autocomplete function used by the module is the following one.

 * Menu callback for the autocomplete results.
function node_reference_autocomplete($entity_type, $bundle, $field_name, $string = '') {
  $instance = field_info_instance($entity_type, $field_name, $bundle);
  $field = field_info_field($field_name);

  $options = array(
    'string' => $string,
    'match' => $instance['widget']['settings']['autocomplete_match'],
    'limit' => 10,
  $references = node_reference_potential_references($field, $options);

  $matches = array();
  foreach ($references as $id => $row) {
    // Markup is fine in autocompletion results (might happen when rendered
    // through Views) but we want to remove hyperlinks.
    $suggestion = preg_replace('/<a href="([^<]*)">([^<]*)<\/a>/', '$2', $row['rendered']);
    // Add a class wrapper for a few required CSS overrides.
    $matches[$row['title'] . " [nid:$id]"] = '<div class="reference-autocomplete">' . $suggestion . '</div>';

  • This completely depends on what is returned from the function returned defined in #autocomplete_path. Can you edit the question and add that function? – AjitS Jun 23 '15 at 6:41
  • Adding the node ID is done to help users who have to edit the reference field. Suppose there are three nodes using ABC as title whose node ID are 5, 20, and 45. Users would see ABC repeated three times, but they could not understand which of the nodes is being referred, and if they just need to change the reference to the node #5 into references to node #87, they would have a hell out it to understand which of those three titles is referring to node #5. – kiamlaluno Jun 23 '15 at 7:13
  • 1
    Also, I didn't check all the code used by the module, but I suspect that removing the node ID is going to break the code: at the end, the module needs the node ID, not the node title. – kiamlaluno Jun 23 '15 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.