LittleSound/slimeform

Feature Request: Add `rule` to the return value of `useForm()`

xuzuodong opened this issue · 5 comments

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.

It might be useful. You could implement it and raise up a Pull Request if you wish.

@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?

What happened? I remember I have released it 😳

It looks like it got rollbacked on npm...

I have re-released v0.8.0 and it should be fine now.

Thanks so much for your quick response! 😄 @LittleSound