primait/pyxis-components/7.3.0

NOTE: the latest version is 9.0.3

Prima.Pyxis.Form.CheckboxFlag

Configuration

type Flag model msg

Represent the opaque Flag configuration.

Configuration Methods

flag : (model -> Maybe Bool) -> (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 : Attribute msg -> Flag model msg -> Flag model msg

Adds a generic Html.Attribute to the Input.

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

Sets a disabled to the Flag config.

withLabel : 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 Type) -> Flag model msg -> Flag model msg

Adds a Validation rule to the Flag.