Use new validated min/max field attributes in place of obsolete non-validated versions.

This commit is contained in:
Dillon Kearns 2022-06-23 10:29:28 -07:00
parent 3ea5ef6e3a
commit 5e9492d45a
3 changed files with 12 additions and 30 deletions

View File

@ -289,7 +289,7 @@ form =
|> Form.field "price"
(Field.int { invalid = \_ -> "Invalid int" }
|> Field.required "Required"
|> Field.withMin (Form.Value.int 0)
|> Field.withMin (Form.Value.int 1) "Price must be at least $1"
|> Field.withInitialValue (\{ smoothie } -> Form.Value.int smoothie.price)
)
|> Form.field "imageUrl"

View File

@ -6,7 +6,6 @@ module Pages.Field exposing
, required, withClientValidation, withInitialValue
, email, password, search, telephone, url, textarea
, withMax, withMin, withStep, withMinLength, withMaxLength
, withMinChecked, withMaxChecked
, No(..), Yes(..)
)
@ -48,11 +47,6 @@ module Pages.Field exposing
@docs withMax, withMin, withStep, withMinLength, withMaxLength
## Temporary Names
@docs withMinChecked, withMaxChecked
## Phantom Options
@docs No, Yes
@ -548,8 +542,8 @@ withInitialValue toInitialValue (Field field kind) =
{-| -}
withMinChecked : Form.Value.Value valueType -> error -> Field error parsed data kind { constraints | min : valueType } -> Field error parsed data kind constraints
withMinChecked min error (Field field kind) =
withMin : Form.Value.Value valueType -> error -> Field error parsed data kind { constraints | min : valueType } -> Field error parsed data kind constraints
withMin min error (Field field kind) =
Field
{ initialValue = field.initialValue
, serverValidation = field.serverValidation
@ -639,8 +633,8 @@ isEmptyValue value =
{-| -}
withMaxChecked : Form.Value.Value valueType -> error -> Field error parsed data kind { constraints | max : valueType } -> Field error parsed data kind constraints
withMaxChecked max error (Field field kind) =
withMax : Form.Value.Value valueType -> error -> Field error parsed data kind { constraints | max : valueType } -> Field error parsed data kind constraints
withMax max error (Field field kind) =
Field
{ initialValue = field.initialValue
, serverValidation = field.serverValidation
@ -670,18 +664,6 @@ withMaxChecked max error (Field field kind) =
kind
{-| -}
withMin : Form.Value.Value valueType -> Field msg error value view { constraints | min : valueType } -> Field msg error value view constraints
withMin min field =
withStringProperty ( "min", Form.Value.toString min ) field
{-| -}
withMax : Form.Value.Value valueType -> Field msg error value view { constraints | max : valueType } -> Field msg error value view constraints
withMax max field =
withStringProperty ( "max", Form.Value.toString max ) field
{-| -}
withStep : Form.Value.Value valueType -> Field msg error value view { constraints | step : valueType } -> Field msg error value view constraints
withStep max field =

View File

@ -47,7 +47,7 @@ all =
\() ->
Field.int { invalid = \_ -> "Invalid" }
|> Field.required "Required"
|> Field.withMinChecked (Value.int 100) "Must be at least 100"
|> Field.withMin (Value.int 100) "Must be at least 100"
--|> Field.withMax (Value.int 200)
|> expect
[ ( Just "", Err [ "Required" ] )
@ -60,8 +60,8 @@ all =
\() ->
Field.float { invalid = \_ -> "Invalid" }
|> Field.required "Required"
|> Field.withMinChecked (Value.float 100) "Must be at least 100"
|> Field.withMaxChecked (Value.float 200) "Too large"
|> Field.withMin (Value.float 100) "Must be at least 100"
|> Field.withMax (Value.float 200) "Too large"
|> expect
[ ( Just "", Err [ "Required" ] )
, ( Nothing, Err [ "Required" ] )
@ -98,8 +98,8 @@ all =
\() ->
Field.date { invalid = \_ -> "Invalid" }
|> Field.required "Required"
|> Field.withMinChecked (Value.date (Date.fromRataDie 738156)) "Must be 2022 or later"
|> Field.withMaxChecked (Value.date (Date.fromRataDie 738158)) "Choose an earlier date"
|> Field.withMin (Value.date (Date.fromRataDie 738156)) "Must be 2022 or later"
|> Field.withMax (Value.date (Date.fromRataDie 738158)) "Choose an earlier date"
|> expect
[ ( Just "", Err [ "Required" ] )
, ( Nothing, Err [ "Required" ] )
@ -112,8 +112,8 @@ all =
, test "optional date with range" <|
\() ->
Field.date { invalid = \_ -> "Invalid" }
|> Field.withMinChecked (Value.date (Date.fromRataDie 738156)) "Must be 2022 or later"
|> Field.withMaxChecked (Value.date (Date.fromRataDie 738158)) "Choose an earlier date"
|> Field.withMin (Value.date (Date.fromRataDie 738156)) "Must be 2022 or later"
|> Field.withMax (Value.date (Date.fromRataDie 738158)) "Choose an earlier date"
|> expect
[ ( Just "", Ok Nothing )
, ( Nothing, Ok Nothing )