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?
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);
}
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?)