"Using Vee-validate to validate on blur can help avoid submitting a form with

Currently, I have implemented vee-validate to validate a form in vue.js. The validation is set to trigger on blur, and there is also a submit button that should validate all fields in the form upon clicking.

The problem arises when I click the submit button after entering some input - only the blur event gets fired to validate the input field. The submit event, however, fails to trigger at first attempt. It's only after clicking the button again that the submit event finally kicks in.

<form v-on:submit.prevent="submit" autocomplete="off">
    <div>
      <div>{{ errors.first('carNumber') }}</div>
      <input v-model="carNumber" name="carNumber" v-validate="'numeric'"/>
      <button type="submit">Submit</button>
    </div>
</form>

For reference, you can check out the sample code here: https://jsfiddle.net/2u6n7xfr/35/

To reproduce the issue, follow these steps:

  1. Enter an invalid value in the input field, for example: qwerty.
  2. Click the submit button (Note that the Submit event does not get triggered).
  3. Now input a valid value, such as: 1234.
  4. Click the submit button once more (Again, the Submit event fails to fire).

Answer №1

Substitute

this.$validator.validate("*").then(function(valid) {

With:

this.$validator.validateAll().then(function(valid) {

Check out: https://jsfiddle.net/Ljo9uw1y/

--

The issue you brought up about clicking on the button is connected to its movement upon clicking. It seems that when the submit button moves, the event does not get triggered. For instance, relocating the error message below the button makes the click function properly: jsfiddle.net/5goe4vcf

To address this problem, one solution could be to reduce the size of the error message to prevent a significant downward expansion, and also enlarge the submit button so it remains within the mouse pointer's range during a click.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Postgres Array intersection: finding elements common to two arrays

I'm currently developing a search function based on tags, within a table structure like this CREATE TABLE permission ( id serial primary key, tags varchar(255)[], ); After adding a row with the tags "artist" and "default," I aim ...

How can I maintain the hover color on a button with a text label even when hovering over the text label?

I need help creating a button with a text label that both respond to clicks and have a hover color. The current code I have works, but the hover color is lost when hovering over the text label. How can I modify the code to maintain the hover color even w ...

Quick filtering of array containing RXJS Observables

As I embark on my Angular2 project, the developers have suggested using RXJS Observable over Promises. So far, I've successfully fetched a list of elements (epics) from the server. Now, my challenge is filtering these elements based on an ID. Below i ...

Retrieve the current timestamp within the asynchronous fetch method of NuxtJS

I encountered an issue while using NuxtJS version 2.12.2. I attempted to access $moment inside async fetch, but received the error message app.$moment is not a function. Here is the code snippet in question: pages/_key.vue <template> <div>& ...

ReactJS library encounters "Failed to load PDF file." error intermittently while attempting to view a PDF file

I recently developed a React JS application using create-react-app and decided to incorporate react-pdf for viewing PDF files. However, I've encountered an intermittent issue where the PDF sometimes fails to load. Specifically, when I initially load t ...

Use Selenium IDE to click on an element using JavaScript if the stored variable equals "Yes"

I am attempting to have Selenium IDE click on a checkbox when the stored value 'x' is equal to Yes. After trying the code below, I received an error indicating that Yes is not defined. I'm also unsure which Selenium IDE command should be u ...

What is the best way to transform a current callback API into promises?

Exploring the transition to working with promises poses a challenge when dealing with callback APIs structured as follows: ###1. Handling DOM load or other one-time event: window.onload; // set to callback ... window.onload = function() { }; ###2. Utili ...

User disappears from Firebase after refreshing the page

I've encountered an issue with my Firebase login process. After a page refresh, the user authentication is lost. Even though the user data is stored in LocalStorage, it gets deleted upon refresh. const loginform = document.querySelector('.loginfo ...

Having issues with the sidebar malfunctioning and unsure of the cause

<html> <head> <title></title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> I've been working on creating a sidebar for my website, but it's not functioning as expect ...

Utilize the input type=date value in the date function to obtain a specific format

How can I pass the value of input type=date to a JavaScript date function? In my HTML code, I have used: <input type=date ng-model="dueDate"> <input type="time" ng-model="dueTime"> <button class="button button-block" ng-click="upload_dueda ...

What is the reason that setTimeout does not delay calling a function?

I am looking to develop a straightforward game where a div is duplicated recursively after a short interval. Each new div should have a unique ID (ID+i). The concept is to continuously generate divs that the user must click on to remove before reaching a ...

Retrieve the Smallest Value from an Array of Objects in a JSON document

My data.json contains information about travel deals. I am looking for the minimum cost when arriving in Amsterdam and departing from London. Could someone guide me on how to properly map through this data? { "currency":"EUR", "d ...

Moving information from two modules to the service (Angular 2)

Recently in my Angular2 project, I created two components (users.component and tasks.component) that need to pass data to a service for processing before sending it to the parent component. Code snippet from users.component.ts: Import { Component } fro ...

Chrome console displaying error in vanilla JavaScript: 'Unable to set property of undefined'

Hello, I am a newcomer to chartjs and JavaScript in general. I keep encountering the error "cannot set property of undefined" in the Chrome console. const dataPie = { labels: ['Good Packs', 'Bad Packs'], datasets: [{ la ...

Can you explain what findDOMNode is and why it is no longer supported in StrictMode within the console?

I attempted to create a count-up feature using React visibility sensor and React count up, but encountered an error in the console. Is there a correct solution to this issue? Caution: The use of findDOMNode is deprecated in StrictMode. This method was uti ...

I am encountering difficulties in creating a table as I continuously receive an error message stating: "Unrecognized datatype for attribute 'postagens.titulo'"

I'm experiencing an issue while trying to create a table in my database. Whenever I attempt to launch my server, I encounter a large error message that reads: Error: Unrecognized datatype for attribute "postagens.titulo" const Database = require(&a ...

Combining Arrays with Identical IDs into a Single Object

When two objects in the data array share the same id, only the first one will be chosen and the rest will be discarded. It is important that multiple assets with the same id are grouped together in one object. const myMap = cardDetails.map((card) => { ...

Unexpectedly, the child component within the modal in React Native has been resetting to its default state

In my setup, there is a parent component called LeagueSelect and a child component known as TeamSelect. LeagueSelect functions as a React Native modal that can be adjusted accordingly. An interesting observation I've made is that when I open the Lea ...

Struggling to make a variable pass in an Ajax post script

Having trouble passing the "filename" variable from main.php to save_sign.php. Can anyone provide assistance? main.php <? $filename="222222"; ?> <script> $(document).ready(function() { $('#signArea').signat ...

Implementing role-based authentication in Next.js using Next-auth and Firebase

Currently, I'm in the process of integrating role-based authentication using NextAuth.js into my Next.js application. Despite following the provided documentation meticulously, an error (in profile snippet and callback snippet which I copied from next ...