jQuery UI AutoComplete: Only allow selected valued from suggested list

前端 未结 9 1940
误落风尘
误落风尘 2020-11-30 22:48

I am implementing jQuery UI Autocomplete and am wondering if there is any way to only allow a selection from the suggested results that are

9条回答
  •  既然无缘
    2020-11-30 23:48

    You could also use this:

    change: function(event,ui){
      $(this).val((ui.item ? ui.item.id : ""));
    }
    

    The only drawback I've seen to this is that even if the user enters the full value of an acceptable item, when they move focus from the textfield it will delete the value and they'll have to do it again. The only way they'd be able to enter a value is by selecting it from the list.

    Don't know if that matters to you or not.

提交回复
热议问题