At now Select2 autocomplete widget need 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. #3081956: Allow showing autocomplete results for Drupal fields with empty input string is similar feature request for Drupal code.

So will be good to add configuration of minimum length for autocomplete results (for allowing autocomplete only with 2 or 3 characters too), and allow zero values for show variants immediately on click event.

Will be good to make this configurable in field settings.

CommentFileSizeAuthor
#2 select2_3083898_autocomplete-empty.patch1.37 KBmurz

Comments

Murz created an issue. See original summary.

murz’s picture

Issue summary: View changes
StatusFileSize
new1.37 KB

Here is the patch, that hard-code zero minimum length for autocomplete, and allow empty q in EntityAutocompleteController ajax response.

murz’s picture

Status: Active » Needs work
murz’s picture

murz’s picture

Title: Allow showing autocomplete results for Drupal fields with empty input string » Allow showing autocomplete results for Select2 fields with empty input string
Related issues: -#3083898: Allow showing autocomplete results for Select2 fields with empty input string +#3081956: Allow showing autocomplete results for Drupal fields with empty input string
chr.fritsch’s picture

Status: Needs work » Needs review

I added a PR to allow empty inputs for autocomplete. https://github.com/thunder/select2/pull/72

I don't want to make this configurable because select2 supports so much different configs, it's impossible to make it configurable for everything.
But now you can now easily override that property.

$my_select2_form_element['#select2']['minimumInputLength'] = 0;
murz’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for PR, it works well! About configuration - yes, configuration in UI is not very needed, overriding property in backend is enough.

  • chr.fritsch authored fdaf477 on 8.x-1.x
    Issue #3083898 by Murz, chr.fritsch: Allow empty input string
    
    
chr.fritsch’s picture

Status: Reviewed & tested by the community » Fixed

Done. Thank you

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.