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

test and record multiple validation failures #1031

Closed
bmcmahen opened this issue Jul 31, 2012 · 3 comments
Closed

test and record multiple validation failures #1031

bmcmahen opened this issue Jul 31, 2012 · 3 comments
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature

Comments

@bmcmahen
Copy link

In my Schema, I'm adding multiple validations for a user registration field. Here's an example:

    , email : {
                type: String
            , index: true
            , lowercase: true
            , validate: [
                    {
                            'validator' : validator.isRequired
                        , 'msg' : 'This field is required.'
                    }
                , {
                            'validator' : validator.isEmail
                        , 'msg' : 'This field must contain an Email Address.'

                    }
            ]
        }

I've noticed that it seems to execute the validations starting fromt the last. So if the field is both empty and not an email address upon submission, the validator records the 'Email' validation error and not the 'isRequired' error.

{ message: 'Validation failed',
  name: 'ValidationError',
  errors: 
   { password: 
      { message: 'Validator "This field is required" failed for path password',
        name: 'ValidatorError',
        path: 'password',
        type: 'This field is required' },
     email: 
      { message: 'Validator "This field must contain an Email Address." failed for path email',
        name: 'ValidatorError',
        path: 'email',
        type: 'This field must contain an Email Address.' },
     name: 
      { message: 'Validator "This field is required" failed for path name',
        name: 'ValidatorError',
        path: 'name',
        type: 'This field is required' } },
  body: { name: '', email: '', password: '' } }

I'm wondering if there would be any way to go through all of the validations, regardless if one fails, so that multiple validation error messages could be recorded and sent back to the user. I realize this probably isn't optimal default behaviour, but the option might be nice.

@aheckmann
Copy link
Collaborator

might be nice

@misterdai
Copy link

This is now being tracked by #2612

@vkarpov15
Copy link
Collaborator

Closing this because its been superseded by #2612.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants