SubmitButton inside form tag with onSubmit handler causes submit handler to be called twice
See original GitHub issueIf I set the htmlType to button, it won’t submit twice but form submit using enter key doesn’t work anymore.
Sample code:
<Formik initialValues={{ username: "", password: "" }} onSubmit={this.handleSubmit}>
{props => (
<form className={styles.login} onSubmit={props.handleSubmit}>
<FormItem name="email">
<InputField name="email" placeholder="Email" autoComplete="username"
prefix={<Icon type="user" style={{color: 'rgba(0,0,0,.25)'}}/>}/>
</FormItem>
<FormItem name="password">
<InputField name="password" type="password" placeholder="Password" autoComplete="current-password"
prefix={<Icon type="lock" style={{color: 'rgba(0,0,0,.25)'}}/>}/>
</FormItem>
<FormItem>
<SubmitButton className={styles.submit} type="primary" htmlType="submit" size="large">
Login
</SubmitButton>
</FormItem>
</form>
)}
</Formik>
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Forms onsubmit handler gets called twice when submitting
The submit handler onsubmit is called twice with pressButton and once with click . The submit (post) without submit handler is done once...
Read more >Submit calls function two times - Stack Overflow
In your onsubmit handler, you're submitting the form: form.submit();. If you do that, the handler has to return false, which means you need...
Read more >Javascript: prevent double form submission - The Art of Web
Using JavaScript to disable form buttons and prevent double submission of an online form. Presenting a 'please wait' message while the form ......
Read more >HTMLFormElement: submit event - Web APIs | MDN
The submit event fires when a is submitted. ... Use the event name in methods like addEventListener() , or set an event handler...
Read more >Setting the Form Action with a JavaScript Function
The above markup is for a simple form with two fields and a submit button. We've set an onsubmit listener which will be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

#29 I removed the custom onClick handler on the SubmitButton. Means a
<form>,<Form>(formik helper) or<Form>(formik-antd) helper are needed for SubmitButton to work (as per your suggestion)@n3v3rf411 I am not yet sure what the best approach here is. As a workaround (or solution?) you can set htmlType and onClick props of the SubmitButton like so: