validatorjs icon indicating copy to clipboard operation
validatorjs copied to clipboard

Custom error messages for multiple auto-generated inputs

Open knitevision1 opened this issue 7 years ago • 1 comments

const data = {
  'person.0.name': 'John',
  'person.1.name': 'Kate',
}

const rules = {
  'person.*.name': 'required'
}

const errorMessages = {
  'required.person.*.name': 'Some custom error message' //prints out "The field person.0.name is required"
}

It works when I change key to required.person.0.name but not in the syntax I specified. It seems like what new Validator(data, rules, errorMessages).errors.all() returns can't be mapped to the given error message because it has a placeholder * in it.

How do I modify it in the way so that I don't have to hardcode the indices?

knitevision1 avatar Jun 11 '18 10:06 knitevision1

Old issue, but still happening. Any news here?

danilopolani avatar Jan 13 '20 15:01 danilopolani