Skip to content

Instantly share code, notes, and snippets.

@svoisen
Last active December 24, 2021 16:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svoisen/538d0074c655cdbfe7eef6d8f4e42ef6 to your computer and use it in GitHub Desktop.
Save svoisen/538d0074c655cdbfe7eef6d8f4e42ef6 to your computer and use it in GitHub Desktop.
Handle onEnter in Elm including input value
onEnter : (String -> msg) -> Attribute msg
onEnter tagger =
let
isEnter code =
if code == 13 then
Decode.succeed ""
else
Decode.fail ""
decodeEnter =
Decode.andThen isEnter keyCode
in
on "keydown" <| Decode.map2(\key value -> tagger value) decodeEnter targetValue
@vikikamath
Copy link

Thanks for this snippet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment