From c345f9daa28e0c174b35413addf78df0a793f8c1 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sat, 1 Aug 2015 00:31:36 +0200 Subject: Adding error feedbacks when adding a payment --- src/client/Model/View/Payment/Add.elm | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/client/Model/View/Payment/Add.elm (limited to 'src/client/Model/View/Payment/Add.elm') diff --git a/src/client/Model/View/Payment/Add.elm b/src/client/Model/View/Payment/Add.elm new file mode 100644 index 0000000..ff64388 --- /dev/null +++ b/src/client/Model/View/Payment/Add.elm @@ -0,0 +1,36 @@ +module Model.View.Payment.Add + ( AddPayment + , initAddPayment + , validateName + , validateCost + ) where + +import Result as Result exposing (Result(..)) + +import Utils.Validation exposing (..) + +type alias AddPayment = + { name : String + , nameError : Maybe String + , cost : String + , costError : Maybe String + } + +initAddPayment : AddPayment +initAddPayment = + { name = "" + , nameError = Nothing + , cost = "" + , costError = Nothing + } + +validateName : String -> Result String String +validateName name = + name + |> validateNonEmpty "The name is required." + +validateCost : String -> Result String Int +validateCost cost = + cost + |> validateNonEmpty "The cost is required." + |> flip Result.andThen (validateNumber "The cost must be a number.") -- cgit v1.2.3