final-form / react-final-form

🏁 High performance subscription-based form state management for React
https://final-form.org/react
MIT License
7.39k stars 481 forks source link

OnSubmit doesn't work #919

Open Maxim1saev opened 3 years ago

Maxim1saev commented 3 years ago

image

Hello! We use "final-form": "4.20.2", the submission stopped working when it was passed to the rff component you have to explicitly transfer the handler to onclick

image

Previously, everything worked correctly

Thanks in advance!)

tjb042 commented 3 years ago

I believe you need to explicitly set the form's onSubmit to the FinalFormRenderProps handleSubmit value. Notice how the example from the react-final-form docs sets the form element's onSubmit from the render props:

<Form onSubmit={onSubmit}>
  {props => (
    <form onSubmit={props.handleSubmit}>

      ... fields go here...

      <button type="submit">Submit</button>
    </form>
  )}
</Form>

Once that value is set the form should submit properly. You'll also want to make sure that the button element you're using to trigger the form has a type of "submit".

Maxim1saev commented 3 years ago

@tjb042 it is your version that does not work

BATCOH commented 3 years ago

I made a sandbox with an example, and it seems to work fine. @Maxim1905 can you provide a minimal reproducible sandbox or repo with the error you are facing? It's hard to say what might be wrong without seeing more code.

bluSCALE4 commented 3 years ago

Looks like your button is in the footer portion of a modal. That means it may not be nested so it may need to follow external submit pattern or make use of FormSpy. It would be better to give a complete example than screenshots as you're leaving a lot to the imagination.