mikeerickson / validatorjs

A data validation library in JavaScript for the browser and Node.js, inspired by Laravel's Validator.
https://www.npmjs.com/package/validatorjs
MIT License
1.77k stars 280 forks source link

Return different from laravel #61

Closed sunupf closed 9 years ago

sunupf commented 9 years ago

In laravel when I create rule

'name'=> 'min:4|max:22|required'

and I just fill the name input with space it's return "The name field is required."

In validatorjs when I create rule

{name:'min:6|max:20|required'}

then I fill the name input with space it's return

{ name:
   [
      'The name must be at least 6 characters.',
      'The name field is required.'
   ] 
}

I think the first error should be "the name field is required", isn't?

garygreen commented 9 years ago

Laravel probably is returning both errors, but you only see the first one.

sunupf commented 9 years ago

yeah I was thought that, that's why I'm asking why not place the required error first then character length.

But, after try some validation, I believe laravel just return required error, without character length error. I was check it using dd()

garygreen commented 9 years ago

Well you are adding the required rule last so why would it be the first error? Really confused.

sunupf commented 9 years ago

Yeah I know that :) . But on validatorjs npm page, validatorjs said "Validation library based on Laravel's Validator class" and laravel will return required error first even we add it at the last place and just return required message.

But if it's how validatorjs work on validation (a little bit different than laravel) then it's ok

garygreen commented 9 years ago

Ha, well your right it's not entirely a complete rewrite/clone of Laravels validator so there will be some differences. I've actually updated the npm description so it more accurately reflects the "inspired" type theme.

I personally always put the order of most important validations left to right. I have been thinking about adding a stopOnFirstError type option as well, as generally you output the first for each field rather than list them all, might increase performance a bit.

sunupf commented 9 years ago

Ya, that option will be nice.

So I''ll close this issue. I think it's not an issue anymore :).

Thank you.