choonkeat/nativeform/1.0.0

NOTE: the latest version is 2.1.2

NativeForm

Using browser document to decode the current values of forms at anytime.

Types

type Value
= OneValue String
| ManyValues (List String)

Values from form fields are either String or List String

e.g. values for input [ type_ "number" ] [] will still be a String since and is entirely up to your application to convert and validate it with String.toInt or String.toFloat

Helper

decoder : String -> Decoder (List ( String, Value ))

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