Rename functions.

This commit is contained in:
Dillon Kearns 2022-07-24 09:21:55 +02:00
parent 1a8df4e6d2
commit c853df574b
4 changed files with 14 additions and 14 deletions

View File

@ -234,7 +234,7 @@ form =
Validation.succeed ( passwordValue, passwordConfirmationValue )
else
Validation.fail2 passwordConfirmation "Must match password"
Validation.fail passwordConfirmation "Must match password"
)
password
passwordConfirmation
@ -250,7 +250,7 @@ form =
|> Validation.andThen
(\validated ->
if Date.toRataDie validated.checkIn >= Date.toRataDie validated.checkOut then
Validation.succeed validated |> Validation.withError2 checkin "Must be before checkout"
Validation.succeed validated |> Validation.withError checkin "Must be before checkout"
else
Validation.succeed validated

View File

@ -153,7 +153,7 @@ dependentParser =
Validation.succeed passwordValue
else
Validation.fail2 passwordConfirmation "Must match password"
Validation.fail passwordConfirmation "Must match password"
)
password
passwordConfirmation

View File

@ -1,7 +1,7 @@
module Form.Validation exposing
( Validation, andMap, andThen, fromMaybe, fromResult, map, map2, parseWithError, succeed, withFallback
( Validation, andMap, andThen, fail, fromMaybe, fromResult, map, map2, parseWithError, succeed, withError, withErrorIf, withFallback
, value
, fail2, fieldName, withError2, withErrorIf2
, fieldName
)
{-|
@ -58,22 +58,22 @@ parseWithError parsed ( key, error ) =
{-| -}
fail2 : Validation error parsed1 field -> error -> Validation error parsed Never
fail2 (Validation _ key _) parsed =
fail : Validation error parsed1 field -> error -> Validation error parsed Never
fail (Validation _ key _) parsed =
-- TODO need to prevent Never fields from being used
Validation Nothing Nothing ( Nothing, Dict.singleton (key |> Maybe.withDefault "") [ parsed ] )
{-| -}
withError2 : Validation error parsed1 field -> error -> Validation error parsed2 named -> Validation error parsed2 named
withError2 (Validation _ key _) error (Validation viewField name ( maybeParsedA, errorsA )) =
withError : Validation error parsed1 field -> error -> Validation error parsed2 named -> Validation error parsed2 named
withError (Validation _ key _) error (Validation viewField name ( maybeParsedA, errorsA )) =
-- TODO need to prevent Never fields from being used
Validation viewField name ( maybeParsedA, errorsA |> insertIfNonempty (key |> Maybe.withDefault "") [ error ] )
{-| -}
withErrorIf2 : Bool -> Validation error ignored field -> error -> Validation error parsed named -> Validation error parsed named
withErrorIf2 includeError (Validation _ key _) error (Validation viewField name ( maybeParsedA, errorsA )) =
withErrorIf : Bool -> Validation error ignored field -> error -> Validation error parsed named -> Validation error parsed named
withErrorIf includeError (Validation _ key _) error (Validation viewField name ( maybeParsedA, errorsA )) =
-- TODO use something like { field : kind } for type variable to check that it represents a field
Validation viewField
name

View File

@ -29,7 +29,7 @@ all =
Validation.succeed
(\passwordValue passwordConfirmationValue ->
Validation.succeed { password = passwordValue }
|> Validation.withErrorIf2 (passwordValue /= passwordConfirmationValue)
|> Validation.withErrorIf (passwordValue /= passwordConfirmationValue)
passwordConfirmation
"Must match password"
)
@ -177,7 +177,7 @@ all =
(\checkinValue checkoutValue ->
Validation.succeed ( checkinValue, checkoutValue )
|> (if Date.toRataDie checkinValue >= Date.toRataDie checkoutValue then
Validation.withError2 checkin "Must be before checkout"
Validation.withError checkin "Must be before checkout"
else
identity
@ -250,7 +250,7 @@ all =
Validation.succeed { password = passwordValue }
else
Validation.fail2 passwordConfirmation "Must match password"
Validation.fail passwordConfirmation "Must match password"
)
|> Validation.andMap password
|> Validation.andMap passwordConfirmation