jquery autocomplete that validates entered value

一个人想着一个人 提交于 2020-01-15 05:08:08

问题


I am using jquery and looking for a autocomplete that will support the mustMatch option (where the user must enter an exists item name) -> this is not a problem since there are several autocompletes that do so.
The problem is that I need the autocomplete will test the entered value.
For example:

  1. The user enters "England".
  2. A list opened with "England".
  3. The user doesn't hit the list item (don't select England), but just click outside the input.
  4. Most autocompltes that support mustMatch will clear the input because the user doesn't select from the list. I am looking for an autocomplete that will validate whether "England "exists or not and act accordingly.

Do you know such autocomplete plugin? Or maybe do you know how can I modify an exists plugin to do so?


回答1:


jQueryUI's autocomplete can do this along with Scott González' autoSelect plugin, combined with the change event on the widget. If you include the plugin, all you should need is:

$("#auto").autocomplete({
    source: ['England', 'Germany', 'Denmark', 'Sweden', 'France', 'Greece', 'Italy'],
    change: function (event, ui) {
        if (!ui.item) {
            this.value = '';
        }
    }
});

Example: http://jsfiddle.net/qb59C/



来源:https://stackoverflow.com/questions/9750804/jquery-autocomplete-that-validates-entered-value

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