Autocomplete disallow free text entry?

前端 未结 7 1272
忘了有多久
忘了有多久 2020-12-02 15:27

Is it possible to disallow free text entry in the JQuery UI autocomplete widget?

eg I only want the user to be allowed to select from the list of items that are pre

7条回答
  •  旧巷少年郎
    2020-12-02 16:03

    Old question, but here:

        var defaultVal = '';
        $('#selector').autocomplete({
            source: url,
            minlength: 2,
            focus: function(event, ui) {
                if (ui != null) {
                    defaultVal = ui.item.label;
                }
            },
            close: function(event, ui) {
                $('#searchBox').val(defaultVal);
            }
        });
    

提交回复
热议问题