Form Example - Table
The source code of this page is available at
Form_Example_Table.elm
.

Operations table example

This is an example of a form that is not completely generate by the Form library but only use single form component and spread them inside existing element, like the table in the example below.

Boilerplate

  • Store an instance of the form state in the model
    type alias Model =
        { formState : R10.Form.State }
  • Initialize with default values
    initModel =
        { formState = R10.Form.initState }
  • 1 Message
    type Msg = MsgForm R10.Form.Msg
  • 1 Update entry
    update msg model =
        case msg of
            MsgForm formMsg ->
                { model | formState = R10.Form.update formMsg model.formState }

and this is all you need as boilerplate.

Form elements generation

To generate checkboxes:

    R10.Form.Element.checkbox model.formState MsgForm 0
    R10.Form.Element.checkbox model.formState MsgForm 1
    R10.Form.Element.checkbox model.formState MsgForm 2
    R10.Form.Element.checkbox model.formState MsgForm 3
    etc...

Retrieveing data

To get the list of touched indexes:

    Dict.keys model.formState.fieldState

To get the list of checked indexes:

    Dict.keys <| Dict.filter (\_ v -> stringToBool v.value) model.formState.fieldState

Working demo

Name
Date
Operation 1
2020.02.02
Operation 2
2020.02.02
Operation 3
2020.02.02
Operation 4
2020.02.02
Operation 5
2020.02.02
Operation 6
2020.02.02
Operation 7
2020.02.02
Operation 8
2020.02.02
Operation 9
2020.02.02
Operation 10
2020.02.02
Operation 11
2020.02.02
Operation 12
2020.02.02
Operation 13
2020.02.02
Operation 14
2020.02.02
Operation 15
2020.02.02
Operation 16
2020.02.02
Operation 17
2020.02.02
Operation 18
2020.02.02
Operation 19
2020.02.02
Operation 20
2020.02.02
Touched: []
Checked: []