Feature Request: Add `rule` to the return value of `useForm()`
See original GitHub issueAdd rule
to the return value of useForm()
, so that I can validate a value before assigning it into form:
const {
form,
rule, // new
} = useForm({
form: () => {
return {
foo: ''
}
},
rule: {
foo: (v) => !!v.length || 'Foo required!',
},
})
const myFoo = 'bar'
const isMyFooValid = rule.foo.validate(myFoo) // true
if (isMyFooValid) {
form.foo = myFoo
}
I think it can be more flexible and convenient in some cases.
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
useForm | React Hook Form - Simple React forms validation
This option allows you to configure the validation strategy before a user submits the form that is happened during onSubmit event by invoking...
Read more >Advanced Usage - React Hook Form
React Hook Form has support for native form validation, which lets you validate inputs with your own rules. Since most of us have...
Read more >useForm - register - Simple React forms validation
This method allows you to register an input or select element and apply validation rules to React Hook Form. Validation rules are all...
Read more >useForm - reset - React Hook Form
Rules. For controlled components you will need to pass defaultValues to useForm in order to reset the Controller components' value.
Read more >useForm - setValue - React Hook Form
This function allows you to dynamically set the value of a registered field and have the options to validate and update the form...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks so much for your quick response! 😄 @LittleSound
I have re-released v0.8.0 and it should be fine now.