Grrrr ondragover

Trying to implement some drag and drop. My code has so far used

onStopAll "dragover" NoOp

where

onStopAll : String -> a -> Attribute a
onStopAll evt msgCreator =
    onWithOptions evt
        { stopPropagation = True, preventDefault = True }
        (Jdec.succeed msgCreator)

It works, but gives me loads of NoOps which is affecting performance. I found https://medium.com/elm-shorts/elm-drag-and-drop-game-630205556d2 and then tried:

attribute "ondragover" "return false"

That fixes everything. But what I had first tried was variations on

onSkipMsg : String -> Attribute msg
onSkipMsg evt =
    onWithOptions evt
        { stopPropagation = False, preventDefault = True }
        (Json.Decode.fail "no message")

but that didn’t seem to play nicely with the ondrop event I also need to handle. Anyone know what is the difference

1 Like

Removing the ondragover will not produce any message right? or am I missing something you are trying to do?

Just to mention it, any “on…” attribute hack is not a sustainable solution even if pretty useful. It is considered as an escape hatch in Elm to include JS code and won’t be possible in the next version.

Yes, i know that using JS is not allowed - hence this question about how to avoid the ‘escape hatch’. But having an ondragover seems to be indispensable in theory and in practise

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.