Last active
June 21, 2017 20:53
-
-
Save JesseHerrick/e3a31c1f68bb4f33f502fd6f68d656ab to your computer and use it in GitHub Desktop.
Force selection of TypeAhead.JS result before form can be submitted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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