question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access form `onSubmit` event data?

See original GitHub issue

Question?

I’m using withFormik and I currently have 2 separate submit buttons in my form, and I need to identify which one has been clicked in my handleSubmit function, but event data isn’t passed along. Any ideas how I could do that?

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
victordidenkocommented, Feb 20, 2018

Why not pass event object as a third argument to onSubmit (handleSubmit)?

Let me give an example: There is non-standard feature in Chrome, called “Credentials API”, which allows developer to save and use passwords to/from browser. One of constructors for PasswordCredential (docs) accepts HTMLFormElement. So I need to pass HTML form to it, in case authorisation was successful and I want to save credentials. So how am I supposed to write my own handler, if I need HTML form inside submitForm, to pass it to my API/service call/action?

I can make PR for that

6reactions
AnoplexAdmincommented, Aug 6, 2022

Not edge case. Many developers have complex forms with multiple submits. I was hoping I could use Formik to simplify the forms in my application, but I don’t have much confidence at this point. The fact that the owner dismisses good ideas with terse comments such as “You can make your own handler…” is not helping the situation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get form data in ReactJS - Stack Overflow
There are a few ways to do this: 1) Get values from array of form elements by index handleSubmit = (event) => {...
Read more >
3 Ways to Get Form Data onSubmit in React - Designcise
We can access a form control element by its (zero-based) index in the form, in the following way: const handleSubmit = (event) => ......
Read more >
HTMLFormElement: submit event - Web APIs | MDN
The submit event fires when the user clicks a submit button ( <button> or <input type="submit">) or presses Enter while editing a field...
Read more >
How to Get the Value of a Form Input on Submit in React
Set an onSubmit event handler on the form element. Access the value of the input field in the onSubmit event handler. For example:....
Read more >
onsubmit Event - W3Schools
The onsubmit event occurs when a form is submitted. Browser Support. Event. onsubmit, Yes, Yes, Yes, Yes, Yes ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found