Formik: Form submits on any button click

Created on 17 Jun 2019  路  3Comments  路  Source: formium/formik

馃悰 Bug report

Current Behavior

https://cl.ly/1ae43a21c4e2

Expected behavior

I don't expect the form to submit when I click any button that does not have type="submit" or has the submit handler explicitly set on the button.

Reproducible example

Formik template: https://codesandbox.io/s/formik-example-rfj49

Suggested solution(s)


Only bind the submission handler to buttons with type="submit" and don't bind to all buttons rendered in the form.

Additional context

Your environment

| Software | Version(s) |
| ---------------- | ---------- |
| Formik | 1.5.7
| React | 16.8.6
| TypeScript |
| Browser | Chrome
| npm/Yarn | npm
| Operating System | macOS

Most helpful comment

Figured out the thing with this issue is you need to explicitly pass type="button", since type="submit" is the default HTML value, as you can see on the screenshot above. So this is not formik-related

All 3 comments

Closing this as this is not a Formik issue. After reading MDN docs, it's actually normal form element behavior to submit any buttons that do not have the type="button" attribute listed. See the below example:

https://codesandbox.io/embed/formik-example-rfj49

@antgonzales Could you please provide and MDN link? Actually in the article about button tag it is pointed out that type="button" has no default browser behaviour. Here's the link, here's a screenshot:
Screenshot from 2019-09-09 19-53-11

Here's a link to the codesandbox that demonstrates buttons behaviour:
https://codesandbox.io/s/winter-violet-rme7d

Figured out the thing with this issue is you need to explicitly pass type="button", since type="submit" is the default HTML value, as you can see on the screenshot above. So this is not formik-related

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PeerHartmann picture PeerHartmann  路  3Comments

jeffbski picture jeffbski  路  3Comments

ancashoria picture ancashoria  路  3Comments

outaTiME picture outaTiME  路  3Comments

green-pickle picture green-pickle  路  3Comments