revalidate icon indicating copy to clipboard operation
revalidate copied to clipboard

How to get field value in message creator function?

Open zoxon opened this issue 4 years ago • 1 comments

Thank you for this library. I'm trying to create a custom validator using createValidator helper In the message I need use current value, how to achieve this?

It looks something like this

const myValidator = createValidator(
  message => value => message,
  (field, value) => `${field} has value ${value}`
);

zoxon avatar Mar 14 '20 17:03 zoxon

Experiments today and find that. Return function instead of string, and apply value in validator implementation. What pitfalls are there?

const myValidator = createValidator(
  message => value => message(value),
  (field) => (value) => `${field} has value ${value}`
);

zoxon avatar Mar 16 '20 03:03 zoxon