I'm pretty sure there is a simple way to solve this but of course being a complete newbie to JS, I couldn't find the solution for this.
Currently my code has an autocomplete call to ajax to get search results, like this :
<input type="text" id="search" name="search">
....
<button type="submit" class="button large" id="programsearch">Search</button>
$('#search').autocomplete({
source: '/ajax-get-data',
minLength: 3,
autoFocus: true,
delay: 100
});
$( "#search" ).on( "autocompletechange", function( event, ui ) {
if (! ui.item) {
$(this).val('').attr('placeholder','try again - choose from the list');
}
});
So if you don't select from the list and click the search button, the input clears out into an empty field and the validator will see it as empty and will throw an error. However, if you type something and you get a drop down list but you don't select from the list, when you hit the enter key, it will submit. How can I tie in a condition where if nothing from the list has been selected (but there is a value in the input field) that the enter key will be disabled? I tried to tie in a .keypress()
function but it mostly disables the enter key entirely.