primait / pyxis-components / Prima.Pyxis.Form.CheckboxFlag

Configuration


type Flag model msg

Represent the opaque Flag configuration.

Configuration Methods

flag : (model -> Maybe Basics.Bool) -> (Basics.Bool -> msg) -> String -> Flag model msg

Create a Flag.

Rendering

render : model -> Flag model msg -> List (Html msg)

Renders the Input.

import Html
import Prima.Pyxis.Form.Flag as Flag
import Prima.Pyxis.Form.Validation as Validation

...

type Msg =
    OnCheck Bool

type alias Model =
    { privacy: Maybe Bool }

...

view : Html Msg
view =
    Html.div
        []
        (Flag.flag .privacy OnInput
            |> Input.withValidation (Maybe.andThen validate << .privacy)
        )

validate : Maybe Bool -> Validation.Type
validate privacy=
    if isJust privacy then
        Just <| Validation.ErrorWithMessage "Privacy cannot be blank".
    else
        Nothing

Options

withAttribute : Html.Attribute msg -> Flag model msg -> Flag model msg

Adds a generic Html.Attribute to the Input.

withDisabled : Basics.Bool -> Flag model msg -> Flag model msg

Sets a disabled to the Flag config.

withLabel : Prima.Pyxis.Form.Label.Label msg -> Flag model msg -> Flag model msg

Adds a Label Html.Attribute to the Flag.

withName : String -> Flag model msg -> Flag model msg

Adds a name Html.Attribute to the Flag.

Event Options

withOnBlur : msg -> Flag model msg -> Flag model msg

Attaches the onBlur event to the Flag.

withOnFocus : msg -> Flag model msg -> Flag model msg

Attaches the onFocus event to the Flag.

Validation

withValidation : (model -> Maybe Prima.Pyxis.Form.Validation.Type) -> Flag model msg -> Flag model msg

Adds a Validation rule to the Flag.