R
R
ruslanbm292021-05-31 18:52:08
Vue.js
ruslanbm29, 2021-05-31 18:52:08

Why does v-on:click fire when I press Enter?

Hello, there is a form, if you enter text and press Enter, then "clearQuery ()" is triggered and the field is cleared. The "clearQuery()" event itself is bound to a button to quickly clear the field. But the idea is that it should only work when the mouse directly clicks on it v-on:click.left. And when you press Enter, the form should submit.

<form method = "GET" class = "row align-items-center" action ="/search/index.php" >
  <div class = "query" v-bind:class = "{ 'query-small': !isEmptyField || isEdit }">
    <label class = "col-12" for = "#searchQuery" >Поиск врачей, клиник, диагностик, анализов, городов</label>
          <input name = "query" class = "col-12" type="text" id = "searchQuery" autocomplete="off" v-model.trim = "query" @focus = "focusQuery()" @blur = "blurQuery()" @click = "clickQuery()" required minlength = "3" />
    <button class = "close" v-bind:class = "{ 'active' : !isEmptyField }" v-on:click.left = "clearQuery()"></button>
  </div>
<button class = "search" type = "submit">
  <span class = "d-none d-md-inline-block">Найти</span>
  <img class = "d-inline-block d-md-none" src = "{THEME}/img/icons/search.png" />
</button>
</form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-05-31
@ruslanbm29

Vue has nothing to do with it, the usual legacy logic of the form behavior:

<form>
  <input />
  <button onclick="alert('Такие дела')"></button>
</form>

It has been dragging on since the days when the web was "not serious", and browsers believed that thinking for crooked webmasters and considering enter as a click is for everyone's benefit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question