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

Array wildcard validation is broken #205

Closed vladshcherbin closed 7 years ago

vladshcherbin commented 7 years ago

From the docs, this example:

const data = {
  users: [
    {
      name: 'John',
      bio: {
        age: 28,
        education: {
          primary: 'Elementary School',
          secondary: 'Secondary School'
        }
      }
    }
  ]
}

const rules = {
  'users.*.name': 'required',
  'users.*.bio.age': 'min:18',
  'users.*.bio.education.primary': 'string',
  'users.*.bio.education.secondary': 'string'
}

const validation = new Validator(data, rules)

if (validation.fails()) {
  console.log(validation.errors.all())
}

It gives error:

screen shot 2017-07-21 at 10 50 08 am

The field is actually defined, but the error is given and error key is a string without array index.

Package version - 3.13.3

alanhr commented 7 years ago

Hi @VladShcherbin , the wildcard validation has not been added yet. :/

vladshcherbin commented 7 years ago

@alanhr yes, I found out that although it was added more than a month ago, a new version is still not published. I linked this issue to https://github.com/skaterdav85/validatorjs/issues/204, docs are misleading now.

Thank you, hope a new version will be released soon.

mikeerickson commented 7 years ago

@VladShcherbin I am aiming to have a new release by EOD Wednesday @alanhr

vladshcherbin commented 7 years ago

@mikeerickson hey, any news on a new release?

vladshcherbin commented 7 years ago

Fixed in 3.13.4.