我正在尝试在Material.Textfield组件中侦听onEnter事件时遇到问题。我想我应该使用Options.on和Decoder来实现它,但我不知道如何实现解码器。任何帮助赞赏
[ Card.actions []
[
Textfield.render Mdl [ 1 ] mdl [ Options.on "keydown" someDecoder, Options.onInput ChatInput] []
]
]
答案 0 :(得分:5)
使用Material.Options.on解决它,以创建自定义事件处理程序
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"