toastal / select-prism / Html.SelectPrism

selectp and selectpm allow a user to push ADTs in and get ADTs out of a <select>

Selects

selectp : Monocle.Prism.Prism String a -> (Result String a -> msg) -> a -> List (Html.Attribute msg) -> List ( String, a ) -> Html msg

selectp is wrapping up the idea of select box from a generic comparable. However, Elm does everything through strings -- which is why we’re using the Prism. That Prism onus is on you. The args are:

  1. Prism from a String to our thing a
  2. A function from the attempt to get--Result String a, where a is our thing--to a msg for the onChange
  3. The selected value
  4. List of Html.Attributes for the <select> so you can have custom classes, etc.
  5. List tuples of ( String, a ) where the String is the label for the option and the a is our thing.

selectpm : Monocle.Prism.Prism String a -> (List (Result String a) -> msg) -> List a -> List (Html.Attribute msg) -> List ( String, a ) -> Html msg

Like selectp, but a <select multiple> which takes a list of selected values and the Msg needs to be a list of results. Note: selectOptions isn’t support in Internet Explorer and I don’t care enough to support it (and maybe you shouldn’t either).