简体   繁体   中英

jQuery UI Autocomplete: minLength needed when having multiple search terms

In this demo: http://jqueryui.com/autocomplete/#multiple

Whenever you manually type in a term and press ", ", the autocomplete automatically displays a list of all terms, which can be troublesome if you have a list of 100,000 terms.

So how do you stop autocomplete from activating after ", "?

And how do you set a minimum length for each term in the input before autocomplete activates?

To handle events when typing and after searching:

  $('.selector').on( "autocompletesearch", function( event, ui ) {
      var text=$('.selector').val();
      if(text[text.length-1]==',') //This validation will do the trick you want (ie: prevent to load everything after you type a ",")
          event.preventDefault();
  } );

jsfiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM