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

前端 未结 13 965
一向
一向 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:41

    Late reply but might help someone!

    Considering the two events in autocomplete widget

    1) change - triggered when field is blurred and value is changed.

    2) response - triggered when the search completes and the menu is shown.

    Modify the change and response events as follows:

    change : function(event,ui)
    {  
    if(!ui.item){
    $("selector").val("");
    }
    },
    
    response : function(event,ui){
    if(ui.content.length==0){
      $("selector").val("");
    }
    }
    

    Hope this helps!

提交回复
热议问题