jquery Google type suggest with restrict to list

孤街浪徒 提交于 2019-12-08 12:28:43

问题


I currently have functionality on a page to give a user suggestions based on what they type in a text box (jquery suggest). The functionality I would like to add is to restrict what gets selected / entered into the text box to only be items in the list. Basically like a combobox which restricts its selections to what's in the list.

One thought I had is to verify that the entry in the textbox matches to an item in the list. I would have to alert the user that what is entered isn't allowed (or maybe there is a way to keep them typing other characters?), it's OK, but not real clean ui.

I figure someone on SO has done something like this; if someone has an idea to achieve this functionality please let me know.


The basic jquery I used:

<script type="text/javascript">
    $(function() {
        $('#autocomplete').autocomplete("getPcodes.aspx", { mustMatch: true, autoFill:true, multipleSeparator: "; ", minChars:3 });
    });
</script>

There are a lot of nice options with the autocomplete. I was using a suggest jquery before, but I think I will opt for this one instead.


回答1:


The jQuery Autocomplete plugin lets you force the user to select an option from the returned dataset.

Check option mustMatch in http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions:

If set to true, the autocompleter will only allow results that are presented by the backend. Note that illegal values result in an empty input box.



来源:https://stackoverflow.com/questions/728596/jquery-google-type-suggest-with-restrict-to-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!