Is there any way to control number of results in an autocomplete field?

Usually node reference autocomplete fields provide 10 results. I want to increase that number.

Is there any global configuration available? How can I alter that number?


2 Answers 2


You will have to make a custom module to alter the result of autocomplete coming from node reference module. This example(taken from here) is for 20 result, you can increase/decrease according to your need.

function MYMODULE_menu_alter(&$menu) {
  if (isset($menu['nodereference/autocomplete'])) {
    $menu['nodereference/autocomplete']['page callback'] = 'MYMODULE_nodereference_autocomplete';
function MYMODULE_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>';
  • i think this is for drupal 6, i tried these code in my module and not working. i cleared my cache also
    – user17543
    Jan 31, 2014 at 7:27
  • You can try in same manner for D7 as well. Find the autocomplete path & then inside see what things are available for you to alter..
    – RajeevK
    Jan 31, 2014 at 7:42

In Drupal 8 you can configure the autocomplete limit match_limit directly in the field settings. This works fine for select2_entity_reference fields.

If you cannot modify the field settings because there are already data, export the field configuration with drush cex, modify the match_limit and import the modified config with drush cim.

(For url link fields, a different approach is needed: How to display more than 10 items in link widget autocomplete?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.