mirror of
https://github.com/cupcakearmy/formhero.git
synced 2024-12-22 16:16:24 +00:00
Update README.md
This commit is contained in:
parent
1e2ad56d6a
commit
43db9630a4
15
README.md
15
README.md
@ -188,7 +188,9 @@ const initial = {
|
||||
|
||||
### Validators
|
||||
|
||||
A validator is an object that taked in either a `RegExp` or a `Function` (can be async). Optionally you can pass a message string that will be displayed instead of the default one.
|
||||
A validator is an object that taked in either a `RegExp` or a `Function` (can be async) or an array of those. Optionally you can pass a message string that will be displayed instead of the default one.
|
||||
|
||||
A validator functions takes the current value as input and should return a `boolean` or a `string`. If returned `true` the input counts as valid, if `false` it's not. If you pass a string formhero will treat it as not valid and display the string returned as error message.
|
||||
|
||||
###### Example: Regular Expression
|
||||
|
||||
@ -238,6 +240,17 @@ const validators = {
|
||||
}
|
||||
```
|
||||
|
||||
###### Example: Dynamic Error Message
|
||||
|
||||
```javascript
|
||||
const validators = {
|
||||
username: async (s: string) => {
|
||||
const taken = await API.isUsernameTaken(s)
|
||||
return taken ? 'Username is taken': true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
Sometimes it's practical to have some different default values when using for example react-native or some other framework where the default `value`, `onChange` and `(e)=> e.target.value` do not apply.
|
||||
|
Loading…
Reference in New Issue
Block a user