gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 13:13:12 24 4
gpt4 key购买 nike

我有这样的输入:

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.

最佳答案

您可以创建“模糊”处理程序的变体,它会像这样提取 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)

关于Elm Html.Events - 将输入值传递给 onBlur 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42893783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com