我有这样的意见:
inputName player =
input
[ type_ "text"
, onInput (Msgs.ChangeName player)
, value player
]
为添加到输入的每个字符创建Msgs.ChangeName。
我希望在用户离开输入后更新模型,但onBlur没有关于输入的任何有效负载:
inputName player =
input
[ type_ "text"
, onBlur (Msgs.ChangeName player)
, value player
]
上面的代码无法编译以错误结尾:
The 1st entry has this type:
Html (String -> Msg)
But the 2nd is:
Html (Msg)
Hint: It looks like a function needs 1 more argument.
答案 0 :(得分:6)
你可以在“模糊”处理程序上创建一个变体,它会像这样拉出target.value
:
import Html.Events exposing (on, targetValue)
import Json.Decode as Json
onBlurWithTargetValue : (String -> msg) -> Attribute msg
onBlurWithTargetValue tagger =
on "blur" (Json.map tagger targetValue)