At now Drupal autocomplete form fields (eg entity reference autocomplete) needs to type at least one symbol for show field autocomplete results.
But in many situations users don't know what to type in form field, and good to show top of available options to user via simple mouse click on field, without any typing. Replacing autocomplete to select is bad idea, when select contain 1000+ options.
Solution for this problem is enabling searching autocomplete results with empty string, but this is hardcoded in Drupal core web/core/modules/system/src/Controller/EntityAutocompleteController.php
:
public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key) {
$matches = [];
// Get the typed string from the URL, if it exists.
if ($input = $request->query->get('q')) {
Quick easy hack is enable calling "getMatches" for empty q
get argument via changing to this:
public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key) {
$matches = [];
// Get the typed string from the URL, if it exists.
$input = $request->query->get('q');
if ($input !== NULL) {
Other solutions maybe use some keyword (eg q=_ALL_
) for show all results, use additional argument (?q=&show-empty=1
).
On field widget settings side will be good to add separate checkbox "Allow autocomplete for empty string", or maybe combine with "Minimum string length for autocomplete = 0", and separate setting for form fields with entity_autocomplete
type.
What do you think about this idea?