Skip to content

Instantly share code, notes, and snippets.

@JesseHerrick
Last active June 21, 2017 20:53
Show Gist options
  • Save JesseHerrick/e3a31c1f68bb4f33f502fd6f68d656ab to your computer and use it in GitHub Desktop.
Save JesseHerrick/e3a31c1f68bb4f33f502fd6f68d656ab to your computer and use it in GitHub Desktop.
Force selection of TypeAhead.JS result before form can be submitted.
var checkAutocompleteInput = function() {
if ($('#autocomplete').find('.tt-selectable').length === 0) { // "#autocomplete" is the autocomplete input menu section
$('.actions input').attr('disabled', 'disabled') // ".actions input" is the Submit button for the form
} else {
$('.actions input').removeAttr('disabled')
}
};
$('#autocomplete .typeahead').typeahead({...}, {...}).on('typeahead:render', function(e) {
$('#autocomplete').parent().find('.tt-selectable:first').addClass('tt-cursor');
checkAutocompleteInput()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment