Formik: Access form `onSubmit` event data?

Created on 17 Jan 2018  路  5Comments  路  Source: formium/formik

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!

Most helpful comment

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

All 5 comments

Funny, I just ran into this issue with Redux-Form so I thought I would take a look at this library to see how they handled it.

You can make your own handler that calls submitForm instead of using handleSubmit

Getting the event object inside of handleSubmit would be useful in some cases.

These tend to be edge cases where you should call your own handler and submitForm

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jucesr picture Jucesr  路  3Comments

green-pickle picture green-pickle  路  3Comments

Jungwoo-An picture Jungwoo-An  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments