Skip to content Skip to sidebar Skip to footer

Save Data From Many Forms Using GetFieldValue()

I try to save data from 2 form (Main and SubForm) using getFieldValue(). Here should appear both form data: Now i get an empty object when i click save handler. If i remove the &

Solution 1:

You need to define 2 refs, one for each form.

const mainFormRef = useRef();
const subFormRef = useRef();

and set these refs on respective forms

<Form
  name="main"
  ref={mainFormRef}
  ....
>
  ....
</Form>

<SubForm myRef={subFormRef} />

finally, inside save function, call getFieldValue on both refs

const save = () => {
    console.log(mainFormRef.current.getFieldValue());
    console.log(subFormRef.current.getFieldValue());
};

Post a Comment for "Save Data From Many Forms Using GetFieldValue()"