ozmat / elm-forms / Forms.Field

Field represents a Form field

Fields


type alias Field comparable =
Internal.Field comparable

A Field can be :

It is looked-up using comparable so a Field String uses a String as field key


type alias Fields comparable =
Internal.Fields comparable

Fields regroups several Field and represents all your form fields.

Creation

myFormFields : Fields String
myFormFields =
    fields
        [ ( "some-input", input )
        , ( "some-select", select )
        , ( "some-checkbox", checkbox )
        , ( "some-group",
          , group
                [ ( "some-other-field", input)
                , ...
                ]
          )
        ]

fields : List ( comparable, Field comparable ) -> Fields comparable

Creates a Fields using a List. This is the top-level function when creating form fields

input : Field comparable

Creates an input Field with the default string Value

select : Field comparable

Creates a select Field with the default string Value

checkbox : Field comparable

Creates a checkbox Field with the default bool Value

group : List ( comparable, Field comparable ) -> Field comparable

Creates a fieldgroup using a List

Using a default value

myFormFields : Fields String
myFormFields =
    fields
        [ ( "some-input", inputWithDefault "Initial value" )
        , ( "some-select", selectWithDefault "Default choice" )
        , ( "some-checkbox", checkboxWithDefault True )
        ]

inputWithDefault : String -> Field comparable

Creates an input Field with a default value

selectWithDefault : String -> Field comparable

Creates a select Field with a default value

checkboxWithDefault : Basics.Bool -> Field comparable

Creates a checkbox Field with a default value