Using browser document to decode the current values of forms at anytime.
Given the id attribute of a <form> tag, we can decode the current
form values into a List of key values.
view model =
form [ id "edituserform123" ]
[]
update msg model =
( { model
| formFields =
NativeForm.decoder "edituserform123" model.document
|> Result.withDefault []
}
, Cmd.none
)NOTE: We are returning a List instead of Dict because on form submit, duplicate
names are preserved. So we are preserving them here too.
https://developer.mozilla.org/en-US/docs/Web/API/Document/forms https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/elements
Values from form fields are either
StringorList Stringe.g. values for
input [ type_ "number" ] []will still be aStringsince and is entirely up to your application to convert and validate it withString.toIntorString.toFloat