Orasund/elm-ui-widgets/1.0.0

NOTE: the latest version is 3.4.0

Widget.ValidatedInput

The validated Input is a wrapper around Input.text. They can validate the input and return an error if nessarry.

Basics

type Model err a
type Msg
{ value : a
, validator : String -> Result err a
, toString : a -> String
}
-> Model err a

The initial state contains

  • value: starting value
  • validator: a vaidation function (a decoder)
  • toString: a function that returns a string representation
update : Msg -> Model err a -> Model err a
List (Attribute msg)
-> Model err a
-> { msgMapper : Msg -> msg
, placeholder : Maybe (Placeholder msg)
, label : String
, readOnly : a -> Element msg
}
-> Element msg

the view function, the parameters include

  • msgMapper: A function wrapping the Msg into a msg
  • placeholder: See Element.text for more information
  • label: The (hidden) label of the input (needed for screen readers)
  • readOnly: a representation of the validated value (clicking on the element will turn on edit mode)

Access the Model

getError : Model err a -> Maybe err

returns the error (if one exists)

getRaw : Model err a -> String

returns the raw value (the value that the user currently sees)

getValue : Model err a -> a

returns the value (the value that has been last successfully validated)