jaredpalmer / formik

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

onSubmit is not triggered if multiple buttons present in the form #3915

Closed hashedalgorithm closed 5 months ago

hashedalgorithm commented 7 months ago

Bug report

Current Behavior

` <div className={cn("flex gap-4 items-center", { "justify-between": currentSection === 1, "justify-end": currentSection === 0, })}

{currentSection === 1 && (

)}

{currentSection === 1 ? ( )}

`

I am using Shadcn Component. So, I have these buttons in my form. I need to trigger onsubmit only on certain button(Create Button). But it does'nt trigger onsubmit. I even disabled validation. nothing works.

Aditional Context

If i explicitly mention onClick for that button it works. like this onClick={() => props.handleSubmit()}

Expected behavior

I have explicitly mentioned the button type as "submit" for the submission button and "button" for others. It should trigger onsubmit onclicking create button.

Reproducible example

Use multiple buttons in form.

Software Version(s)
Formik 2.4.5
React latest
TypeScript latest
Browser Brave Version 1.60.118 Chromium: 119.0.6045.163 (Official Build) (64-bit)
npm/Yarn 1.22.19
Operating System Windows 11 Home
karfau commented 7 months ago

I have no idea why I was mentioned as part of this.