M
M
mxbeat2020-07-24 13:31:08
JavaScript
mxbeat, 2020-07-24 13:31:08

How to disable the default event for the Enter key on Android?

I have a form

<form action="#" class="form">
    <input class="form__input" type="text" name="name" required>
    <input class="form__input" type="tel" name="tel" required>
    <button class="form__button" type="submit">Submit</button>
</form>


and jQuery code

$('.form .form__input').keydown(function (event) {
    if (event.keyCode == 13) {
      event.preventDefault();
      $(this).blur();
      return false;
    }
});


You can see it in action here: https://codepen.io/maxbeat/pen/XWXGZLM

I need the field to simply remove focus (i.e. blur) after entering text in the field and pressing the Enter key. On PC and iOs everything works as it should, but on Android after pressing the Enter key it goes to the next form field, how to disable this transition?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question