Recommended pattern for calling e.preventDefault()
See original GitHub issueIssue Description
I had/have this problem where when I submit a form
like, this
<form onSubmit={{validateAll(this.onSubmit)}}>
<input type="submit" value="Submit" />
</form>
The validation errors would flash and then the page would “redirect” from /submit
to /submit?
, clearing the state. Once on /submit?
, the form validation works as you would expect, and does not submit until the form is valid. I don’t really understand why but I don’t think this is related to revalidation
.
One thing I did notice is that none of the examples use form
- they use a div
and a custom button.onClick
handler. Just curious about what the suggested pattern for calling e.preventDefault()
is. I personally prefer to use a form
as I find it to be a bit more semmantically correct.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
How to correctly use preventDefault(), stopPropagation(), or ...
We can use it to prevent this default bubbling behaviour so that the event is only registered by the element it is called...
Read more >e.preventDefault && e.preventDefault() - Stack Overflow
I'm accustomed to seeing e.preventDefault() called without the conditional. When would e.preventDefault be falsy and is it best practice to use ...
Read more >The difference between 'return false;' and 'e.preventDefault();'
Prevents the for example click event to be triggered, but if the selector used for the click event is in a scope of...
Read more >Event.preventDefault() - Web APIs | MDN
Calling preventDefault() during any stage of event flow cancels the event, meaning that any default action normally taken by the implementation ...
Read more >jQuery event.preventDefault() Method - GeeksforGeeks
The jQuery preventDefault() Method is used to stop the default action of selected element to occur. It is also used to check whether ......
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
Yeah, and we want it to stay in userland, ye? It makes a lot of sense
Excellent!