parthi82
parthi82

Reputation: 483

Listening for onEnter events in elm-mdl Textfield

I’m facing a problem trying to listen for onEnter events in Material.Textfield component. I think i should implement it using Options.on and a Decoder, but i’m not sure how to implement a decoder. any help appreciated

  [ Card.actions []
      [ 
         Textfield.render Mdl [ 1 ] mdl [ Options.on "keydown" someDecoder, Options.onInput ChatInput] []
      ]
   ]

Upvotes: 2

Views: 259

Answers (1)

parthi82
parthi82

Reputation: 483

solved it by using Material.Options.on to create a custom event handler

import Html.Events exposing (keyCode)
import Json.Decode as JD
import Material.Options as Options


Textfield.render Mdl [ 1 ] mdl [ Options.on "keydown" (JD.andThen isEnter keyCode) ] []


isEnter : number -> JD.Decoder Msg
isEnter code =
   if code == 13 then
      JD.succeed SendMsg
   else
      JD.fail "not Enter"

Upvotes: 5

Related Questions