How do I use preventDefault in elm? Say on a keyboard event:
keyDown keyCode model =
case keyCode of
13 -> -- Enter key
model
if we don't want the default behaviour?
Html.Events has methods for it, but I don't understand how to use it in practice.
preventDefault() Prevents the browsers default behaviour (such as opening a link), but does not stop the event from bubbling up the DOM.
The event. preventDefault() prevents the browsers default behaviour, but does not stop the event from bubbling up the DOM. The event. stopPropagation() prevents the event from bubbling up the DOM, but does not stop the browsers default behaviour.
You can now use the library elm-community/html-extra for that, it provides you the onClickPreventDefault
and onClickStopPropagation
functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With