0

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

1
  • r u using this code Commented Mar 7, 2011 at 9:18

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

case KEY.RETURN: if( selectCurrent() ) { // stop default to prevent a form submit, Opera needs special handling event.preventDefault(); blockSubmit = true; return false; } break; I HAD THIS...BUT I DONT KNOW WHERE TO MODIFY I TRIED BY COMMENTING THE LINES BUT NO USE :(

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.