Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
Wait for event to fire before blurring

I have an autocomplete input, and when I click on an element, it does something. For simplification purposes, the thing is here "console.log(element)". The thing is that when I click an element, it blurs the input, and blurring the input destroys the elements of the list. If I wait a few milliseconds, the click event is handled, but if not, it only takes into account the blur event. I made an example with the two options:

var app = new Vue({
  el: '#app',
  data: {
    list: ['1', '2'],
  },
  methods: {
    handleBlurWithPause: async function () {
      await new Promise((r) => setTimeout(r, 300));
      console.log('Blurred with pause');
      this.list = [];
    },
    handleBlur: function () {
      console.log('Blurred');
      this.list = [];
    },
    handleClick: function (e) {
      console.log(e);
    },
    resetList: function () {
      this.list = ['1','2'];
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <input
    placeholder="With pause"
    type="text"
    @blur="handleBlurWithPause" />
  <input
    placeholder="Without pause"
    type="text"
    @blur="handleBlur" />
  <ul>
    <li
      v-for="elt in list"
      @click="handleClick(elt)">
      {{ elt }}
    </li>
  </ul>
  <button
    @click="resetList">
    Reset
  </button>
</div>

My question is: is there a better way to wait for the click event before handling the blur event? The async/await line seems very amateur for me.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!