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.

Recommended pattern for calling e.preventDefault()

See original GitHub issue

I had/have this problem where when I submit a form like, this

<form onSubmit={{validateAll(this.onSubmit)}}>
  <input type="submit" value="Submit" />

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:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

bookercodescommented, Jun 26, 2017

Yeah, and we want it to stay in userland, ye? It makes a lot of sense

busypeoplescommented, Jun 26, 2017


Read more comments on GitHub >

github_iconTop 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 >

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 Post

No results found

github_iconTop Related Hashnode Post

No results found