firefox autocomplete 'enter' keypress on autocomplete triggering enter on textbox

You could store the value of the field on key down, and then check again on key up. If more than 1 character is different in the string from one key press, it's safe to assume that an autocomplete item was selected and enter should be ignored.

The only case where this wouldn't work is when you have a field like: [email protected] and you are selecting an autocomplete item with only the final letter added, the enter key would submit the form unintentionally.

Hope that gets us started at least. I am trying to sort out a bulletproof solution as well. I will update if I find one.

EDIT

Screw above. Sorted it out. If you check for the enter key on key up, and the input field value isn't the same on both key down/up, you can assume an autocomplete item was selected.

var loginCurrentInput = '';

$('input').keydown(function(e) {

  loginCurrentInput = $(this).val();

}

$('input').keyup(function(e) {

  //if enter key pressed
  if(e.keyCode == 13) {

    //check for changed input value
    if($(this).val() != loginCurrentInput) {

      loginCurrentInput = $(this).val();
      return false;

    }

    $('#button').trigger('click');

  }

}