Elm Html.Events - 将输入值传递给onBlur消息

dan*_*ula 4 elm

我有这样的输入:

inputName player =
    input
        [ type_ "text"
        , onInput (Msgs.ChangeName player)
        , value player
        ]
Run Code Online (Sandbox Code Playgroud)

它为添加到输入的每个字符创建Msgs.ChangeName.

我宁愿在用户离开输入后更新模型,但onBlur没有关于输入的任何有效负载:

inputName player =
    input
        [ type_ "text"
        , onBlur (Msgs.ChangeName player)
        , value player
        ]
Run Code Online (Sandbox Code Playgroud)

上面的代码不会以错误结束编译:

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.
Run Code Online (Sandbox Code Playgroud)

Cha*_*ert 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)
Run Code Online (Sandbox Code Playgroud)