kutyel/elm-form/1.0.0

Renamed to scrive/elm-form. It is published under that name, and new versions come out there.

Versions published as kutyel/elm-form still install under that name. 1 version of 1 come from the new location (see their notes).

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/scrive/elm-form.

What we checked: The repo moved to github.com/scrive/elm-form. Rebuilt with git archive from commit 36826458dd77 of https://github.com/scrive/elm-form (zip prefix kutyel-elm-form-3682645/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 fb9d51c1d4d0daaf65a2aa4c5e28dfbf14ccaceb.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/kutyel/elm-form/zipball/1.0.0/

Form

Simple forms made easy: A Dict implementation of the core Json.Decode API, with state lifecycle and input helpers for the views.

Types

type Msg
= NoOp
| Focus String
| Blur String
| Input String InputType FieldValue
| Append String
| RemoveItem String Int
| Submit
| Validate
| Reset (List ( String, Field ))

Form messages for update.

= Text
| Textarea
| Select
| Radio
| Checkbox

Input types to determine live validation behaviour.

type Form customError output

Form to embed in your model. Type parameters are:

  • customError - a custom error type to extend built-in errors (set to () if you don't need it)
  • output - the type of the validation output.
type alias FieldState e a =
{ path : String
, value : Maybe a
, error : Maybe (ErrorValue e)
, liveError : Maybe (ErrorValue e)
, isDirty : Bool
, isChanged : Bool
, hasFocus : Bool
}

Field state containing all necessary data for view and update, can be retrived with Form.getFieldAsString or Form.getFieldAsBool.

  • path - qualified path of the field in the form, with dots for nested fields (field.subfield)
  • value - a Maybe of the requested type
  • error - a Maybe of the field error
  • liveError - same but with added logic for live validation (see getLiveErrorAt impl)
  • isDirty - if the field content has been changed since last validation
  • isChanged - if the field value has changed since last init/reset
  • hasFocus - if the field is currently focused

Init/update lifecyle

initial : List ( String, Field ) -> Validation e output -> Form e output

Initial form state. See Form.Field for initial fields, and Form.Validate for validation.

update : Validation e output -> Msg -> Form e output -> Form e output

Update form state with the given message

Field state accessors

getFieldAsString : String -> Form e o -> FieldState e String

Get field state at path, with value as a String.

getFieldAsBool : String -> Form e o -> FieldState e Bool

Get field state at path, with value as a Bool.

getListIndexes : String -> Form e o -> List Int

return a list of indexes so one can build qualified names of fields in list.

Global state accessors

getFocus : Form e o -> Maybe String

Return currently focused field, if any.

isSubmitted : Form e o -> Bool

Get form submission state. Useful to show errors on unchanged fields.

getErrors : Form e o -> List ( String, ErrorValue e )

Get list of errors on qualified paths.

getOutput : Form e o -> Maybe o

Get form output, in case of validation success.

getChangedFields : Form e o -> Set String

Get set of changed fields.