elm-community / html-extra / Html.Events.Extra

Additional decoders for use with event handlers in html.

Event decoders

charCode : Json.Decode.Decoder (Maybe Char)

Character code for key board events. This is being deprecated, but support for DOM3 Keyboard events is not yet present in most browsers.

Typed event decoders

targetValueFloat : Json.Decode.Decoder Basics.Float

Floating-point target value.

targetValueInt : Json.Decode.Decoder Basics.Int

Integer target value.

targetValueMaybe : Json.Decode.Decoder (Maybe String)

String or empty target value.

targetValueMaybeFloat : Json.Decode.Decoder (Maybe Basics.Float)

Floating-point or empty target value.

targetValueMaybeInt : Json.Decode.Decoder (Maybe Basics.Int)

Integer or empty target value.

targetValueFloatParse : Json.Decode.Decoder Basics.Float

Parse a floating-point value from the input instead of using valueAsNumber. Use this with inputs that do not have a number type.

targetValueIntParse : Json.Decode.Decoder Basics.Int

Parse an integer value from the input instead of using valueAsNumber. Use this with inputs that do not have a number type.

targetValueMaybeFloatParse : Json.Decode.Decoder (Maybe Basics.Float)

Parse an optional floating-point value from the input instead of using valueAsNumber. Use this with inputs that do not have a number type.

targetValueMaybeIntParse : Json.Decode.Decoder (Maybe Basics.Int)

Parse an optional integer value from the input instead of using valueAsNumber. Use this with inputs that do not have a number type.

targetSelectedIndex : Json.Decode.Decoder (Maybe Basics.Int)

Parse the index of the selected option of a select. Returns Nothing in place of the spec's magic value -1.

targetSelectedOptions : Json.Decode.Decoder (List String)

Parse event.target.selectedOptions and return option values.

Event Handlers

onClickPreventDefault : msg -> Html.Attribute msg

Always send msg upon click, preventing the browser's default behavior.

onClickStopPropagation : msg -> Html.Attribute msg

Always send msg upon click, preventing click propagation.

onClickPreventDefaultAndStopPropagation : msg -> Html.Attribute msg

Always send msg upon click, preventing the browser's default behavior and propagation

onEnter : msg -> Html.Attribute msg

When the enter key is released, send the msg. Otherwise, do nothing.

onChange : (String -> msg) -> Html.Attribute msg

An HTML Event attribute that passes the event.target.value to a msg constructor when an input, select, or textarea element has changed.

onMultiSelect : (List String -> msg) -> Html.Attribute msg

Detect change events on multi-choice select elements.

It will grab the string values of event.target.selectedOptions on any change event.

Check out targetSelectedOptions for more details on how this works.

Note: onChange parses event.target.value that doesn't work with multi-choice select elements.

Note 2: selectedOptions is not supported by Internet Explorer.