榆树:提交时清除表格
Elm: clear form on submit
我有一个只有一个字段的简单表单。我想清除表单提交上的字段。我在我的更新功能中清除了我的模型,但文本仍保留在文本输入中。
type alias Model =
{ currentSpelling : String }
type Msg
= MorePlease
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
MorePlease ->
( log "cleared spelling: " { model | currentSpelling = "" }
, fetchWord model.currentSpelling )
view : Model -> Html Msg
view model =
div []
[ Html.form [ onSubmit MorePlease ]
[ input [ type' "text"
, placeholder "Search for your word here"
, onInput NewSpelling
, attribute "autofocus" ""
] []
, text model.currentSpelling
, input [ type' "submit" ] [ text "submit!" ]
]
]
显示model.currentSpelling
的text
在我用更新功能清空它时被清除,但文本输入框仍然填充。知道如何清除它吗?
fetchWord
进行HTTP调用,此处省略
将value model.currentSpelling
添加到属性中
输入元素。这就是你如何控制字符串
html.
中的输入元素内部
我有一个只有一个字段的简单表单。我想清除表单提交上的字段。我在我的更新功能中清除了我的模型,但文本仍保留在文本输入中。
type alias Model =
{ currentSpelling : String }
type Msg
= MorePlease
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
MorePlease ->
( log "cleared spelling: " { model | currentSpelling = "" }
, fetchWord model.currentSpelling )
view : Model -> Html Msg
view model =
div []
[ Html.form [ onSubmit MorePlease ]
[ input [ type' "text"
, placeholder "Search for your word here"
, onInput NewSpelling
, attribute "autofocus" ""
] []
, text model.currentSpelling
, input [ type' "submit" ] [ text "submit!" ]
]
]
显示model.currentSpelling
的text
在我用更新功能清空它时被清除,但文本输入框仍然填充。知道如何清除它吗?
fetchWord
进行HTTP调用,此处省略
将value model.currentSpelling
添加到属性中
输入元素。这就是你如何控制字符串
html.