From 5e9492d45a5492cc4e8bca0b827e2369430faba8 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Thu, 23 Jun 2022 10:29:28 -0700 Subject: [PATCH] Use new validated min/max field attributes in place of obsolete non-validated versions. --- .../smoothies/app/Route/SmoothieId_/Edit.elm | 2 +- src/Pages/Field.elm | 26 +++---------------- tests/FieldTests.elm | 14 +++++----- 3 files changed, 12 insertions(+), 30 deletions(-) diff --git a/examples/smoothies/app/Route/SmoothieId_/Edit.elm b/examples/smoothies/app/Route/SmoothieId_/Edit.elm index 3bf0fbb7..7a9eb3a0 100644 --- a/examples/smoothies/app/Route/SmoothieId_/Edit.elm +++ b/examples/smoothies/app/Route/SmoothieId_/Edit.elm @@ -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" diff --git a/src/Pages/Field.elm b/src/Pages/Field.elm index afdad911..0aa3ae84 100644 --- a/src/Pages/Field.elm +++ b/src/Pages/Field.elm @@ -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 = diff --git a/tests/FieldTests.elm b/tests/FieldTests.elm index f708767c..af34cf00 100644 --- a/tests/FieldTests.elm +++ b/tests/FieldTests.elm @@ -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 )