question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Delay and previous rules get ignored on custom validation

See original GitHub issue

Versions:

  • VueJs: 2.1.0
  • Vee-Validate: 2.0.0-beta.18

Description:

When i use a custom rule the delay gets ignore. The rule gets fired instantly. Also, it seems that the previous rules (in this context “required” and “email”) get ignored this way, because my custom rule always fires, even when the field is failing the required and email rules. I’m kinda used to an Angular library that first checked if the rules (in this context: required and email) were valid. Which makes a bit more sense to me.

Below the rule that check’s if the e-mail address is already used, if so, display an error. I need to do an API call for this. So, if the API says it exists, show an error. If it does not exist, the field is valid.

This all works good. Except when you type your e-mail address in the field, it does the API call immediately. So, if you have a 20 character email address, it fires 20 times.

If this is by design, i would suggest to first check if the previous rules (in this case: required and email) are valid. And after that do the custom rule, using the delay if given.

Steps To Reproduce:

export const checkIfEmailExists = {
  getMessage (field, params, data) {
    return (data && data.message)
  },
  validate (email, fieldName) {
    const payload = {
      email: email
    }
    return Vue.http.post('search/users', payload)
    .then(response => {
      if (response.status === 200 && response.data.length) {
        return {
          valid: false,
          data: {
            message: `There is already an account with this e-mail address. Is that you? <a href="/login">Login</a>`
          }
        }
      } else {
        return {
          valid: true
        }
      }
    })
    .catch(error => {
      console.error('Error checking the e-mail address', error)
      return {
        valid: false,
        data: {
          message: `There was an error checking the e-mail address. Please try again later. Sorry!`
        }
      }
    })
  }
}
VeeValidate.Validator.extend('checkIfEmailExists', ValidatorRules.checkIfEmailExists)
<input type="email" id="email" name="email" placeholder="E-mail address" v-model="email" v-validate.initial="email" data-vv-rules="required|email|checkIfEmailExists" data-vv-delay="1000" :class="{'error': errors.has('email') && submitted }" />

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
logaretmcommented, Feb 11, 2017

@gfviegas Actually never got the chance to work on it, but it is very high on my list and shouldn’t be hard to implement, in a couple of days probably.

2reactions
gfviegascommented, Nov 16, 2017

@assembledadam uuuggh, this is so off topic…

But you just need to use the v-html in your html to render html tags properly

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET MVC custom validator client-side validation not firing
Default attributes were preventing posting a form to the server and my custom attribute was ignored. So this is what I did. Disable...
Read more >
Validation Rule Considerations - Salesforce Help
The detail page of a custom activity field doesn't list associated validation rules. Workflow rules and some processes can invalidate previously valid fields....
Read more >
Custom Data Validation in Excel : formulas and rules - Ablebits
Learn how to use custom Data Validation in Excel with your own rules and formulas. Formula examples to allow only numbers or text...
Read more >
Data validation task settings - AWS Database Migration Service
RecordSuspendDelayInMinutes – Specifies the delay time in minutes before tables are suspended from validation due to error threshold set in FailureMaxCount .
Read more >
Flutter form validation: The complete guide - LogRocket Blog
Editor's note: This article was last updated on 25 February 2022 to include information ... Getting started with form validation in Flutter ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found