Feature Request: Add `rule` to the return value of `useForm()`
xuzuodong opened this issue · 5 comments
xuzuodong commented
Add 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.
LittleSound commented
It might be useful. You could implement it and raise up a Pull Request if you wish.
xuzuodong commented
@LittleSound I want to use the feature in my own project, while I noticed the PR has been merged but the version in npmjs.org is still 0.7.0, could you publish the 0.8.0 at your earliest convenience?
LittleSound commented
What happened? I remember I have released it 😳
It looks like it got rollbacked on npm...
LittleSound commented
I have re-released v0.8.0 and it should be fine now.
xuzuodong commented
Thanks so much for your quick response! 😄 @LittleSound