How to implement “mustMatch” and “selectFirst” in jQuery UI Autocomplete?

前端 未结 13 1015
一向
一向 2020-11-27 11:47

I recently migrated a few of my Autocomplete plugins from the one produced by bassistance to the jQuery UI autocomplete.

How can the \"mustMatch\" and \"selectFirst\

13条回答
  •  鱼传尺愫
    2020-11-27 12:45

    I found this question to be useful.

    I thought I'd post up the code I'm now using (adapted from Esteban Feldman's answer).

    I've added my own mustMatch option, and a CSS class to highlight the issue before resetting the textbox value.

           change: function (event, ui) {
              if (options.mustMatch) {
                var found = $('.ui-autocomplete li').text().search($(this).val());
    
                if (found < 0) {
                  $(this).addClass('ui-autocomplete-nomatch').val('');
                  $(this).delay(1500).removeClass('ui-autocomplete-nomatch', 500);
                }
              }
            }
    

    CSS

    .ui-autocomplete-nomatch { background: white url('../Images/AutocompleteError.gif') right center no-repeat; }
    

提交回复
热议问题