4

I'm using redux-form inside Modal with 'Validate' & 'Cancel' buttons. There's 3 differents form who'll create 3 differents entities in backend. I want to create and dispatch 2/3 independante json.

Is it possible to use 3 differents form inside same page, and validate/submit everything with the same button ?

Thanks for helps.

2 Answers 2

2

Yes, it is possible to submit 3 different forms with a single button. You need to use remote submit - see this example. In your case you would dispatch 3 form names that you want to submit.

Example:

function submitForms() {
  dispatch(submit('FirstOne'))
  dispatch(submit('secondOne'))
}

<Button type="button" onClick={ submitForms } />
Sign up to request clarification or add additional context in comments.

2 Comments

Yep thanks. I tried but i can't dispatch more than one form. <Button type="button" onClick= { () => { dispatch(submit('FirstOne'') dispatch(submit('secondeOne'). }} />. Only the first one is submit :/
@GreGGus I have added an example - I assume this maybe because of the typos in your comment (not sure if you copied it).
0

@Deividas,

You were right, it's working ! My mistake was I added an validate to the second form, so only the first one was really created.

It's make me think about validation ...

function submitForms() {
  dispatch(submit('FirstOne'))  // isn't validate
  dispatch(submit('secondOne')) // is validate
  dispatch(submit('thirdOne'))  // is validate
}

<Button type="button" onClick={ submitForms } />

As you can see, if the firstOne validation is not ok, it will dispatch the second and third form if their own validation is ok.

All my form are "connected", it's like All submit or nothing.

Is it possible to acces 'errors' value or valation inside my sumbit function and do some conditionals things to handle this behavior ?

Anyway, thanks for your help :)

1 Comment

Did you remedy this? What about a promise chain to inspect the result of a promise before executing the next?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.