stormy-gold
stormy-gold11mo ago

Submit a form within another form's onSubmit.

I have 2 forms via useForm
const form_A = useForm({...});
const form_B = useForm({...});
const form_A = useForm({...});
const form_B = useForm({...});
When form_A is submitted, I would also like form_B to be submitted. How would one programatically trigger the submission of form_B when the submission of form_B occurs?
3 Replies
kapa.ai
kapa.ai11mo ago
Hi @UsererOfName. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the extracts, you can use the submit function from the useStepsForm hook to programmatically submit a form. However, the extracts do not provide a direct example of how to trigger the submission of one form based on the submission of another form. Here's a general idea of how you might approach this:
const form_A = useForm({...});
const form_B = useForm({...});

const onSubmitFormA = (e) => {
e.preventDefault();
form_A.submit();
form_B.submit();
};
const form_A = useForm({...});
const form_B = useForm({...});

const onSubmitFormA = (e) => {
e.preventDefault();
form_A.submit();
form_B.submit();
};
In this example, when form_A is submitted, form_B is also submitted. Please note that this is a general idea and might need adjustments based on your specific use case. For more detailed information, you may want to refer to the useStepsForm documentation (https://refine.dev/docs/api-reference/antd/hooks/form/useStepsForm). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai11mo ago
<@1032307923235373217> kapa.ai is still learning and improving, please let us how it did by reacting below
stormy-gold
stormy-gold11mo ago
@kapa.ai Can you provide an example that uses the 'useForm' hook instead of the 'useStepsForm' hook? @kapa.ai Can you provide an example that uses the 'useForm' hook instead of the 'useStepsForm' hook?