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.Validate

Form validation.

Combinators

type alias Validation customError output =
Field -> Result (Error customError) output

A validation is a function that takes a form field and returns a result being either a validation error or the expected object.

field : String -> Validation e a -> Field -> Result (Error e) a

Access the given field in the group.

field "name" string
map : (a -> b) -> Validation e a -> Field -> Result (Error e) b

Map over the result of the validation.

field "myfield" (string |> map String.trim)
succeed : a -> Field -> Result (Error e) a

A validation that always succeeds. Useful for contextual validation.

andThen : (a -> Validation e b) -> Validation e a -> Field -> Result (Error e) b

Apply a new validation to the result of the validation.

field "myfield" (int |> andThen (minInt 10))
andMap : Validation e a -> Validation e (a -> b) -> Field -> Result (Error e) b

Incremental form validation for records with more that 8 fields.

Form.Validate.succeed SomeRecord
    |> andMap (field "foo" string)
    |> andMap (field "bar" string)
customError : e -> Error e

Helper to create a CustomError.

defaultValue : a -> Validation e a -> Field -> Result (Error e) a

Rescue a failed validation with the supplied value.

mapError : (Error e1 -> Error e2) -> Validation e1 a -> Validation e2 a

Call Result.mapError on validation result.

withCustomError : customErr -> Validation e a -> Validation customErr a

Arrange that if a validation fails, it has the given custom error.

field "customerId"
    (V.int
        |> andThen (minInt 1)
        |> andThen (maxInt 9999)
        |> withCustomError InvalidIdentity
    )
sequence : List (Validation e a) -> Validation e (List a)

Combine a list of validations into a validation producing a list of all results.

Fixed-size forms

map2 : (a -> b -> m) -> Validation e a -> Validation e b -> Validation e m

Validation a form with two fields.

(a -> b -> c -> m)
-> Validation e a
-> Validation e b
-> Validation e c
-> Validation e m

Validation a form with three fields.

(a -> b -> c -> d -> m)
-> Validation e a
-> Validation e b
-> Validation e c
-> Validation e d
-> Validation e m

Validation a form with four fields.

(a -> b -> c -> d -> e -> m)
-> Validation err a
-> Validation err b
-> Validation err c
-> Validation err d
-> Validation err e
-> Validation err m

Validation a form with five fields.

(a -> b -> c -> d -> e -> f -> m)
-> Validation err a
-> Validation err b
-> Validation err c
-> Validation err d
-> Validation err e
-> Validation err f
-> Validation err m

Validation a form with six fields.

(a -> b -> c -> d -> e -> f -> g -> m)
-> Validation err a
-> Validation err b
-> Validation err c
-> Validation err d
-> Validation err e
-> Validation err f
-> Validation err g
-> Validation err m

Validation a form with seven fields.

(a -> b -> c -> d -> e -> f -> g -> h -> m)
-> Validation err a
-> Validation err b
-> Validation err c
-> Validation err d
-> Validation err e
-> Validation err f
-> Validation err g
-> Validation err h
-> Validation err m

Validation a form with eight fields.

Type extractors

list : Validation e a -> Field -> Result (Error e) (List a)

Validate a list of fields.

string : Field -> Result (Error e) String

Validation a String.

int : Field -> Result (Error e) Int

Validation an integer using String.toInt.

float : Field -> Result (Error e) Float

Validation a float using String.toFloat.

bool : Field -> Result (Error e) Bool

Validation a Bool.

maybe : Validation e a -> Field -> Result (Error e) (Maybe a)

Transform validation result to Maybe, using Result.toMaybe.

email : Validation e String

Check if the string is a valid email address.

emptyString : Field -> Result (Error e) String

Validate an empty string, otherwise failing with InvalidString. Useful with oneOf for optional fields with format validation.

Common filters

minInt : Int -> Int -> Field -> Result (Error e) Int

Min value for Int.

maxInt : Int -> Int -> Field -> Result (Error e) Int

Max value for Int.

minFloat : Float -> Float -> Field -> Result (Error e) Float

Min value for Float.

maxFloat : Float -> Float -> Field -> Result (Error e) Float

Max value for Float.

minLength : Int -> String -> Field -> Result (Error e) String

Min length for String.

maxLength : Int -> String -> Field -> Result (Error e) String

Max length for String.

nonEmpty : String -> Field -> Result (Error e) String

Fails if String.isEmpty.

format : Regex -> String -> Field -> Result (Error e) String

Validates format of the string.

includedIn : List String -> String -> Field -> Result (Error e) String

Check if the string is included in the given list.

Custom validations

fail : Error e -> Field -> Result (Error e) a

A validation that always fails. Useful for contextual validation.

Validation e a
-> (a -> Result (Error e) b)
-> Field
-> Result (Error e) b

Custom validation for your special cases.

oneOf : List (Validation e a) -> Field -> Result (Error e) a

First successful validation wins, from left to right.