3

I have a node reference field and the auto-complete widget. Right now, It only returns/suggests 10 nodes maximum.

How can i increase the number of nodes suggested by the auto-complete? (Or) better yet make it return all the suggestions?

1

You need to create a custom module and also you need a .info file change 20 to the number you want

function custom_tweaks_menu_alter(&$menu) {
  if (isset($menu['nodereference/autocomplete'])) {
    $menu['nodereference/autocomplete']['page callback'] = 'custom_tweaks_nodereference_autocomplete';
  }
}

function custom_tweaks_nodereference_autocomplete($field_name, $string = '') {
  $fields = content_fields();
  $field = $fields[$field_name];
  $match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains';
  $matches = array();

  $references = _nodereference_potential_references($field, $string, $match, array(), 20);
  foreach ($references as $id => $row) {
    // Add a class wrapper for a few required CSS overrides.
    $matches[$row['title'] ." [nid:$id]"] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>';
  }
  drupal_json($matches);
}

Taken from this source

0

Apply this patch: https://www.drupal.org/node/2185019#comment-11573163 for EntityReference with autocomplete widget.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.