test and record multiple validation failures #1031

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

Projects

None yet

4 participants

@bmcmahen

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

might be nice

@misterdai

This is now being tracked by #2612

@vkarpov15

Closing this because its been superseded by #2612.

@vkarpov15 vkarpov15 closed this Feb 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment