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" |> Form.field "price"
(Field.int { invalid = \_ -> "Invalid int" } (Field.int { invalid = \_ -> "Invalid int" }
|> Field.required "Required" |> 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) |> Field.withInitialValue (\{ smoothie } -> Form.Value.int smoothie.price)
) )
|> Form.field "imageUrl" |> Form.field "imageUrl"

View File

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

View File

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