Availity / availity-reactstrap-validation

Easy to use React validation components compatible for reactstrap.
https://availity.github.io/availity-reactstrap-validation/
MIT License
191 stars 70 forks source link

How defining errorMessage with Custom Validation? #237

Open Vic44tu opened 3 years ago

Vic44tu commented 3 years ago

I would like to use Custom Validation and define error Message. The example given in doc is with async function: validate={{async: this.validate}}

1) is it possible to use custom validate function without async call? 2) is it possible to define simply the errorMessage? I tried (in functional component): validate={{validate: myValidate, errorMessage: "my error msg"}} but myValidate not called validate={{myValidate}} or validate={{validate: myValidate, ...}}; myValidate is called but errorMessage has to be stored and displayed on its own for example with AvFeedback

TheSharpieOne commented 3 years ago
  1. async is just a example key (I used it b/c the example also demonstrates how to do async stuff, but it probably made it less clear), it can be any key (such as myCustomAwesomeCode). IIRC, the key has no special meaning, it just cannot be one of the predefined validation keys.
  2. If the validation function returns a string, that string is used as the error message.