malinoff / elm-uniform / Uniform.Classic

This is a tiny wrapper around Uniform.field and Uniform.viewField that makes all fields editable by default, and does not require you to provide valueState in your values.

Fields

field : (value -> Basics.Bool) -> FieldConfig value output values -> Uniform.FormField value output values

Define a "classic", always-editable form field.

First argument is a function telling if the given value is empty. Useful for custom field types, but if you find yourself working mostly with text fields, take a look at textField.


type alias FieldConfig value output values =
{ parser : value -> Result String output
, value : values -> value
, update : values -> value -> values 
}

Describe how to get, set, parse the field's value.

textField : FieldConfig String output values -> Uniform.FormField String output values

Define a "classic" text field. Not mandatory to use, but can help to shorten your fields definition a bit.

All it does is calling field String.isEmpty.

It is intentional that there are no other similar helpers in the library. I encourage you to implement similar helper functions for your custom value types.

View

viewField : ViewConfig value values element -> Uniform.Field value output values -> element

A type-safe way to view a single field from the filled form's fields.

viewNameField =
    Uniform.viewField viewName

viewAgeField =
    Uniform.viewField viewAge

viewForm model =
    let
        filled =
            Uniform.fill userForm model.formValues
    in
    Html.div
        []
        [ viewNameField
        , viewAgeField
        ]


type alias ViewConfig value values element =
{ value : value
, update : value -> values } -> elemen
}

Describe how to view a form's field.

It is a function that accepts the value to display and the update function that should be called in onInput handler like this:

    viewName { value, update } =
        Html.input
            [ Html.Events.onInput (FormUpdated << update) ]
            , Html.Attributes.value value
            ]
            []