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

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

    I discovered one issue. While the suggestion list is active you can submit your form even if the value doesn't match the suggestion. To dissallow this I added:

    $('form').submit(function() {
            if ($(".ui-autocomplete li:textEquals('" + $(this).val() + "')").size() == 0) {
                $(this).val('');
                $("span").text("Select a valid city").show();
                return false;
            }
    });
    

    This prevents the form from being submitted and displays a message.

提交回复
热议问题