I
I
Igor Bezlepkin2018-06-06 14:37:02
HTML
Igor Bezlepkin, 2018-06-06 14:37:02

How in Vue to abort form submission on pressing enter on input?

There is a form. It has an autocomplete field. So when focus is on it and you press enter, the form flies away. How can this be interrupted?

<form class="form form-settings" @submit.prevent="send">
  <input type="text" v-model="city" />
</form>


methods: {
  send: function () {
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-06-06
@Bezlepkin

The fact is that if there is only one input field in the form, then, according to the specification , pressing enter should lead to submitting the form:

When there is only one single-line text input field in a form, the user agent should accept Enter in that field as a request to submit the form.

What to do? Block default action on enter, add input @keypress.enter.prevent.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question