jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
34.01k stars 2.79k forks source link

Page reloads on submit if form is inside drawer component #3934

Closed ghost closed 11 months ago

ghost commented 11 months ago

Bug report

Current Behavior

Submit btn reloads page if Formik is inside callable component like aside drawer. Any variations of prevent default doesn't solve this problem. If I click on submit btn, page reloads, validation doesn't work and it looks like GET request, because I see query in url.

Screenshot 2024-01-02 at 10 59 48 AM

Suggested solution(s)

How could I solve this?

Your environment

Software Version(s)
Formik 2.4.5
React 18.2.0
TypeScript 4.9.5
Browser Chrome
npm/Yarn NPM
juvpengele commented 11 months ago

Can you add more details of the code you have written so that it can be reproduced ?

ghost commented 11 months ago

Can you add more details of the code you have written so that it can be reproduced ?

Sure! Thank you!

Page with carriers and drawer toggling:

Screenshot 2024-01-03 at 12 13 15 PM

CreateCarrierForm component:

Screenshot 2024-01-03 at 12 11 33 PM

Drawer is quite simple. It contains {children} and toggling by isOpened boolean value. If I separate form from the Drawer - everything working as expected. It looks like submit button inside the drawer calls nothing. Changing { Form } from Formik to plain form onSubmit='...' has no result too, same as dealing with Formik prop on Submit.

juvpengele commented 11 months ago
ghost commented 11 months ago
  • Is console.log displayed ?
  • Can you try
   <Formik
       initialValues={initialValues}}
       validationSchema={createCarrierSchema}
       onSubmit={(values, actions) => {
            actions.setSubmitting(false);
       }}
     >
     ....
   </Formik>

That's the point. This part doesn't work because if I click on 'submit' btn the whole page reloads.

ghost commented 11 months ago

@juvpengele I found the solution. Thank you for your response.

In case anyone needed:

Screenshot 2024-01-03 at 2 17 45 PM