modular-forms icon indicating copy to clipboard operation
modular-forms copied to clipboard

Validate: After triggering form validation once, any subsequent forms added using the insert method will immediately trigger validation.

Open qingzhoufeihu opened this issue 1 year ago • 3 comments

In the "todos" example in the playground, after clicking the submit button to trigger validation, if you click the add button, the newly added item automatically triggers validation. How can we avoid this validation?

https://modularforms.dev/react/playground/todos

step 1: click submit button step2: click add new button

qingzhoufeihu avatar Dec 03 '24 04:12 qingzhoufeihu

Currently you can only avoid it by changing the revalidateOn option of useForm or createForm to 'submit'. What is your use case? Can't you enter a valid value when calling insert?

fabian-hiller avatar Dec 04 '24 04:12 fabian-hiller

Currently you can only avoid it by changing the revalidateOn option of useForm or createForm to 'submit'. What is your use case? Can't you enter a valid value when calling insert?

Thanks for your reply, "blur" works for me.I mean, if I set revalidateOn: "change" and then I click the "add new" button without entering anything in the newly appeared field, why does the new field directly trigger validation and show an error message?

qingzhoufeihu avatar Dec 04 '24 05:12 qingzhoufeihu

This should only happen after the form has already been submitted, but I can see where you are coming from and why the current behavior can be annoying. Perhaps we should offer an option to control this when calling insert.

fabian-hiller avatar Dec 05 '24 04:12 fabian-hiller