Elm: clear form on submit

I have a simple form with one field. I would like to clear the field on the submit form. I clear my model in my update function, but the text remains in the text input.

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!" ] ] ] 

The text display showing model.currentSpelling is cleared when I clear it with the update function, but the text input field remains filled. Any idea how to clean it?

fetchWord makes an HTTP call, but it is omitted here.

+5
source share
1 answer

add value model.currentSpelling to the attributes of the input element. The way you can control a string inside an input element in html.

+10
source

Source: https://habr.com/ru/post/1258365/


All Articles