poppinss / indicative

Indicative is a simple yet powerful data validator for Node.js and browsers. It makes it so simple to write async validations on nested set of data.
https://indicative.adonisjs.com/
MIT License
417 stars 52 forks source link

Custom message for array validation #245

Closed ardyfeb closed 5 years ago

ardyfeb commented 5 years ago

How to set custom message for array validation ?, i have trying like below code but message still showing required validation variant.0.value failed

Package version

5.0.8

Node.js and npm version

latest

Sample Code (to reproduce the issue)

data = {
   variant: [
     {
        value: "wkwkland"
     }
   ]
}

validate(data, {
  'variant.0.value': 'required'
}, {
  'variant.0.value.required': 'Variant value cannot be empty'
})
thetutlage commented 5 years ago

Shouldn't it be variant.0.value.required?

ardyfeb commented 5 years ago

Shouldn't it be variant.0.value.required?

i edited my issue, actually is variant i typo when writing issue

ardyfeb commented 5 years ago

Screenshot from 2019-07-15 17-48-36 here a complete rules and message

thetutlage commented 5 years ago

Works fine for me with this code sample.

const  { validate } = require('indicative/validator')

const data = {
   variant: [{}]
}

validate(data, {
  'variant.0.value': 'required'
}, {
  'variant.0.value.required': 'Variant value cannot be empty'
}).catch(console.error)
thetutlage commented 5 years ago

Here's the live example https://repl.it/@amanvirk/Indicative-example

ardyfeb commented 5 years ago

thanks for your help, solved by upgrading from 5.0.8 to 7.2.0