revalidate
                                
                                 revalidate copied to clipboard
                                
                                    revalidate copied to clipboard
                            
                            
                            
                        Passing "contextual" data into validation method
:wave: @jfairbank !
I often need to validate a field based on some information outside of any of the fields being validated. That's what I mean by "contextual" data in this issue's title. For instance, in a web app that manages books, you may want the books to have a unique name. So to validate the name of one book, the validation method needs all books to know if there is a duplicate.
To do this, would you recommend putting this "extra" data in the object to validated, and then not adding any validation on that key within combineValidators?
To give an example, using the dog example from the docs:
const dogValidator = combineValidators({
  name: composeValidators(
    isAlphabetic,
    createValidator(
      message => (value, allValues) => {
        if (allValues.dogNames.indexOf(value) !== -1) {
          return message;
        }
      },
      field => `${field} must be unique`
    )
  )('Name'),
  age: isNumeric('Age')
});
const result = dogValidator({ name: 'larry', age: 'abc', dogNames: ['larry', 'kathryn'] });
Do you think this is fine, or do you have another suggestion on how best to do this? Thanks!
At first, I tried to do...
 createValidator(
  message => (value, allValues, dogNames) => {
    if (dogNames.indexOf(value) !== -1) {
      return message;
    }
  },
  field => `${field} must be unique`
)
const result = dogValidator({ name: 'larry', age: 'abc'}, ['larry', 'kathryn']);
but that didn't work :)
👋 @jmeas
I think your suggested workaround is fine, albeit a little cumbersome from an API standpoint. I do think that there could be value in passing contextual data as well. Ideally, it would easy to use manually like your example and also work well with redux-form.
I've been a little busy finishing up some features for another OSS project, but I hope to come back and work on revalidate some more soon. If you have any ideas, I'd love to see them and maybe a PR too :)
👌 I'll whip up a PR!