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

indicative.extend not working??? #181

Closed smiley05 closed 6 years ago

smiley05 commented 6 years ago

Hi, Thank you for your great work and support.

When I tried the sample as shown per the docs Iam getting "time is not defined as a validation rule". Please help the following is the sample I tried. Please correct whats wrong? var indicative = require('indicative'); const timeRegex = /([01]?[0-9]|2[0-3]):[0-5]0-9?/

const timeFn = function (data, field, message, args, get) { return new Promise((resolve, reject) => { const fieldValue = get(data, field)

if (fieldValue && !timeRegex.test(fieldValue)) {
  return reject(message)
}

resolve('validation passed')

}) } indicative.time = timeFn; rules = { first_name: 'required', last_name: 'required', time: 'required|time' }

thetutlage commented 6 years ago

First, please format your message properly. It's hard to understand.

Also have you considered the docs? https://indicative.adonisjs.com/docs/api/extend

smiley05 commented 6 years ago

Well thank you for your response. Yes, I followed the docs and tried the same example indicative.time=timeFn, but when I set time in the rules setting as shown, I am getting "time is not defined as a validation rule" error. rules = { time: 'required | time' }

thetutlage commented 6 years ago

Can you point me to the docs which say that you can define rules on the indicative object?

smiley05 commented 6 years ago

I mean from this docs sample only - https://indicative.adonisjs.com/docs/api/extend

thetutlage commented 6 years ago

As per the docs you have to use the validations object and not indicative

const { validations } = require('indicative')
validations.time = timeFn
smiley05 commented 6 years ago

oh yes!!! I didn't understood before, now I got it. Thank you.