Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using preventDefault in Elm

Tags:

elm

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.

like image 768
swelet Avatar asked Aug 11 '16 23:08

swelet


People also ask

Does preventDefault stop bubbling?

preventDefault() Prevents the browsers default behaviour (such as opening a link), but does not stop the event from bubbling up the DOM.

What is event preventDefault () and event stopPropagation ()?

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.


Video Answer


1 Answers

You can now use the library elm-community/html-extra for that, it provides you the onClickPreventDefault and onClickStopPropagation functions.

like image 71
Rogerio Chaves Avatar answered Oct 17 '22 01:10

Rogerio Chaves