1

Is there any way to control number of results in an autocompleted field in drupal?. Usually node reference autocomplete fields provide 10 results, i want to increase the count, is there any global configuration availabe or how can i alter the count?

4

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>';
  }
  drupal_json($matches);
}
  • 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 '14 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 '14 at 7:42

Your Answer

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