Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when use multiple validations show multiple errors #563

Closed
luisenriquegomesportugal opened this issue Dec 14, 2018 · 1 comment · Fixed by #573
Closed

when use multiple validations show multiple errors #563

luisenriquegomesportugal opened this issue Dec 14, 2018 · 1 comment · Fixed by #573

Comments

@luisenriquegomesportugal

Hello, I'm using your component and I realized that when I use multiple validations in the same field it shows several errors on the page, I'll attach photos from the screen for you to understand.

I'm using this scheme:

oSchema  : 
{
  groups : 
  [
    {
      legend : 'Teste',
      fields : 
      [
        {
          type          : "cleave",
          label         : "Data de nascimento",
          model         : "date",
          pattern       : /^\d{2}\/\d{2}\/\d{4}?/,
          required      : true,
          validator     : ["required", "regexp", "number"],
          cleaveOptions : 
          {
            date: true,
            datePattern: ['d', 'm', 'Y'],
            delimiter: '/'
          }
        }
      ]
    }
  ]
}

however, using this schema, it generates this output:
image

I would like you to look at this problem, or guide me to the correct form, if there is one.

I imagine that it is a for in errors, and that it could be changed to a first so it showed only the first error, and when that error was corrected then it showed the other error, and so on.

in addition, the component is very good, very versatile, it helped me a lot, I will always use it, congratulations.

thank you so much.

zoul0813 added a commit to zoul0813/vue-form-generator that referenced this issue Dec 21, 2018
…ltiple validators from returning "this field is required", etc)
@zoul0813
Copy link
Member

The required validator is only needed if you are not validating anything other than a values existence. All built-in validators will return a "this field is required" message if schema.required = true.

Your example is a bit confusing as well, as the value can't validate against the 'regexp' and the 'number' validator since your 'regexp' would not result in a valid number.

All validators that fail are expected to return the failure messages, and display them. This allows the user to see all of the errors and correct the problem, rather than fixing one problem only to be displayed another error.

I've pushed a PR that removes duplicate messages from the errors array, which should resolve this issue. Though you will still see multiple errors if more than one error is generated (and they are unique).

zoul0813 added a commit that referenced this issue Dec 22, 2018
…rrors

Ref #563 - return unique validation errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants