How can I disable free text input with Twitter's Typeahead plugin? All examples and configurations I find, the user 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 options.
The technique is to use .blur to check if valid suggestion is present
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("");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With