jquery-autocomplete
when I hit "enter" to choose an item from the jquery-autocomplete results, the form submits. Why this happens....
i should get the data in the text field and开发者_开发知识库 on second enter the form should submit...
please suggest where to change in autocomplete.js
Thanks in advance
try this:
Find the keydown event on the li, in the autocomplete.js file and then place this line at the end of the keydown`s event handler (it may have some switch statement, you are interested about the 13[ enter key code]),:
return false;
ex:
.keydown(function(e) {
// track last key pressed
lastKeyPressCode = e.keyCode;
switch(e.keyCode) {
case 38: // up
e.preventDefault();
moveSelect(-1);
break;
case 40: // down
e.preventDefault();
moveSelect(1);
break;
case 9: // tab
case 13: // return
if( selectCurrent() ){
// make sure to blur off the current field
$input.get(0).blur();
e.preventDefault();
return false; // ADD THIS !
}
break;
default:
active = -1;
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function(){onChange();}, options.delay);
break;
}
})
this will stop the event to further propagate and submit the form.
精彩评论