DonutReply
DonutReply

Reputation: 3254

Submit form with JS on pressing enter but not when on autocomplete

I've got a form with a custom submit button (not an input[type=submit]). I want the form to submit on pressing enter which the function below does, but it also submits on pressing enter to select a item from a autocomplete dropdown. How do I prevent it from submitting when selecting a autocomplete option?

submitForm.delegate('input','submit',function(e){
    if (e.keyCode === 13) 
        submitForm.trigger('submit');
});

Thanks

Upvotes: 2

Views: 480

Answers (1)

cloakedninjas
cloakedninjas

Reputation: 4176

Put in a validation / completeness check

if (e.keyCode === 13 && submitForm.isComplete()) {
    submitForm.trigger('submit');
}

OR - revert back to a submit button for better semantics, what's the reason for not using it?

Upvotes: 2

Related Questions