Posts
Chat
Members
Info
December 10, 2019 at 3:08pm
Thank you for replying very quick. There are not errors, but I don't want to reset the value of name, only the value of "other"
Please, see me my edited answer.
In my example is not exactly like my code but I had to make it easy and sort, the subform shouldn't be aware of the mainForm, they are independent components
the idea of the subform is to add elements to a list that belongs to the main form
when you add it I want that subform to be cleared
I will try with that reset, but I find it weird the second reset clear the first form
That would be hard in your case. Either you make your main form aware of the value of your sub-form or vice versa
// main aware of sub formfunction MainForm() {const { register, handleSubmit, getValues. reset } = useForm();const handleSubFormSubmit = data => {// do you submission here// then resetconst { name } = getValues({ nest: true });const subForm = {other: "",};reset({name,...subForm})};return (<form onSubmit={handleSubmit(console.log)}><input name="name" ref={register} /><SubForm onSubmit={handleSubFormSubmit} /></form>);}
I don't think the lib has form-scope awareness feature.
I will have to find a way because I have 30 fields or more in my form
also tried in that way and didn't work
everything get reseted
actually look like the library is form-scope aware because the
getValue
of the subform only returns the values of the subform and not the ones from the mainformfor me was weird that getValues and triggerValidatin was form-scope but no the reset
We can continue our discussion here