No free text with Typeahead

How to disable free text input with the Twitter Typeahead plugin? All the examples and configurations that I find can enter custom text. I need the user to NOT be able to enter custom text, but only if the text matches one of the parameters.

+4
source share
1 answer

The method is to use .blur to check for a valid offer

var myData = ["sugg1" , "sugg2" ]; // all data required for typeahead

$("#search").typeahead({source : myData})
                   .blur(validateSelection);

function validateSelection() {
    if(source.indexOf($(this).val()) === -1) 
        $("#search").val("");
}
+3
source

Source: https://habr.com/ru/post/1540593/


All Articles