yoghurt-x86 / easy-forms / Form.Field

This module defines some of the tools to work with fields

Label your field:

withLabel : String -> Field form value state msg error ctx fieldCtx view -> Field form value state msg error ctx fieldCtx view

Add a label to your field. The field is put inside a label tag.

withPlaceholder : String -> Field form value state msg error ctx fieldCtx view -> Field form value state msg error ctx fieldCtx view

Add a placeholder value to a field.

withDescription : String -> Field form value state msg error ctx fieldCtx view -> Field form value state msg error ctx fieldCtx view

Add a short description under a field

Validations:


type alias Hint hint a =
a -> Result hint ()

Hint


type alias GlobalHint ctx hint form =
ctx -> form -> Result hint ()

Global Hint

withHints : List (Hint hint value) -> Field form value state msg hint ctx fieldCtx view -> Field form value state msg hint ctx fieldCtx view

Add hints to a field. When the field is updated all the hints will be tested and displayed if they don't pass.

withGlobalHints : List (GlobalHint ctx hint form) -> Field form value state msg hint ctx fieldCtx view -> Field form value state msg hint ctx fieldCtx view

Add a global hint

notEmpty : hint -> String -> Result hint ()

Fails in case the string is empty or whitespace only

isTrue : hint -> Basics.Bool -> Result hint ()

Fails if false

isDefined : hint -> Maybe a -> Result hint ()

Fails if the Maybe does not contain a value

isEmail : hint -> String -> Result hint ()

Will use a regex to check if a string is in an email shape

Types:


type alias Field form value state msg hint ctx fieldCtx view =
{ view : fieldCtx -> ViewConfig value state hint -> view
, state : Value value state
, update : fieldCtx -> msg -> Value value state -> Value value state
, hints : List hint
, label : Maybe String
, placeholder : Maybe String
, description : Maybe String
, getContext : ctx -> fieldCtx
, hinting : List (Hint hint value)
, globalHinting : List (GlobalHint ctx hint form) 
}

The internal field type.


type FieldMsg msg
    = Blur
    | FieldMsg msg

These messages can be used by the form system


type alias Parser a b hint =
a -> Result hint b

Parse a field to another value.


type alias Value value state =
{ state | value : value }

Every field state needs to have a value


type alias ViewConfig value state hint =
{ state : Value value state
, hints : List hint
, label : Maybe String
, placeholder : Maybe String
, description : Maybe String 
}

The record given to a field view function