diff options
author | Joris | 2017-03-26 23:16:28 +0200 |
---|---|---|
committer | Joris | 2017-03-27 00:17:41 +0200 |
commit | 902acfbdbcc1d59941399753e887479e586e2748 (patch) | |
tree | 0ad90ead3f8bdf0ea7c94462d1577c8e188df469 /src/client/Dialog | |
parent | 8062f1c9c34e9b25d76b22bd6ba2a1a99666279b (diff) |
Improve form validation
- Trim names
- Income amount accepted from 0
- Validate colors
Diffstat (limited to 'src/client/Dialog')
-rw-r--r-- | src/client/Dialog/AddCategory/Model.elm | 8 | ||||
-rw-r--r-- | src/client/Dialog/AddCategory/View.elm | 6 | ||||
-rw-r--r-- | src/client/Dialog/AddIncome/Model.elm | 2 | ||||
-rw-r--r-- | src/client/Dialog/AddPayment/View.elm | 4 |
4 files changed, 11 insertions, 9 deletions
diff --git a/src/client/Dialog/AddCategory/Model.elm b/src/client/Dialog/AddCategory/Model.elm index 7496c2b..3b70482 100644 --- a/src/client/Dialog/AddCategory/Model.elm +++ b/src/client/Dialog/AddCategory/Model.elm @@ -8,14 +8,16 @@ module Dialog.AddCategory.Model exposing ) import Date exposing (Date) -import View.Date as Date +import Dict import Form exposing (Form) import Form.Field as Field exposing (Field) import Form.Validate as Validate exposing (Validation) +import Model.Category exposing (Categories, Category, CategoryId) import Model.Translations exposing (Translations) -import Model.Category exposing (Category, CategoryId) +import Validation +import View.Date as Date type alias Model = { id : Maybe CategoryId @@ -49,4 +51,4 @@ validation = Validate.map3 Model (Validate.field "id" (Validate.maybe Validate.int)) (Validate.field "name" (Validate.string |> Validate.andThen Validate.nonEmpty)) - (Validate.field "color" (Validate.string |> Validate.andThen Validate.nonEmpty)) + (Validate.field "color" Validation.color) diff --git a/src/client/Dialog/AddCategory/View.elm b/src/client/Dialog/AddCategory/View.elm index 6c02351..dc55b60 100644 --- a/src/client/Dialog/AddCategory/View.elm +++ b/src/client/Dialog/AddCategory/View.elm @@ -45,7 +45,7 @@ button loggedData initialForm title buttonContent tooltip = Just message -> Tooltip.show Msg.Tooltip message Nothing -> [] ) - ++ [ onClick (Msg.Dialog <| Dialog.OpenWithUpdate dialogConfig (DialogMsg.Init "categoryname" (DialogMsg.AddCategoryMsg <| Form.Reset initialForm))) ] + ++ [ onClick (Msg.Dialog <| Dialog.OpenWithUpdate dialogConfig (DialogMsg.Init "categoryname" (DialogMsg.AddCategoryMsg (Form.Reset initialForm)))) ] ) [ buttonContent ] @@ -65,8 +65,8 @@ submitForm addCategory = Just data -> case data.id of Just categoryId -> - Msg.Dialog <| Dialog.UpdateAndClose <| Msg.EditCategory categoryId data.name data.color + Msg.Dialog <| Dialog.UpdateAndClose <| Msg.EditCategory categoryId (String.trim data.name) data.color Nothing -> - Msg.Dialog <| Dialog.UpdateAndClose <| Msg.CreateCategory data.name data.color + Msg.Dialog <| Dialog.UpdateAndClose <| Msg.CreateCategory (String.trim data.name) data.color Nothing -> Msg.Dialog <| Dialog.Update <| DialogMsg.AddCategoryMsg <| Form.Submit diff --git a/src/client/Dialog/AddIncome/Model.elm b/src/client/Dialog/AddIncome/Model.elm index ad7b25a..5e2ccf1 100644 --- a/src/client/Dialog/AddIncome/Model.elm +++ b/src/client/Dialog/AddIncome/Model.elm @@ -49,5 +49,5 @@ validation : Validation String Model validation = Validate.map3 Model (Validate.field "id" (Validate.maybe Validate.int)) - (Validate.field "amount" (Validate.int |> Validate.andThen (Validate.minInt 1))) + (Validate.field "amount" (Validate.int |> Validate.andThen (Validate.minInt 0))) (Validate.field "date" Validation.date) diff --git a/src/client/Dialog/AddPayment/View.elm b/src/client/Dialog/AddPayment/View.elm index 078d5b7..66c9f00 100644 --- a/src/client/Dialog/AddPayment/View.elm +++ b/src/client/Dialog/AddPayment/View.elm @@ -86,10 +86,10 @@ submitForm categories paymentCategories addPayment = Just paymentId -> Msg.Dialog <| Dialog.UpdateAndClose - <| Msg.EditPayment paymentId data.name data.cost data.date data.category data.frequency + <| Msg.EditPayment paymentId (String.trim data.name) data.cost data.date data.category data.frequency Nothing -> Msg.Dialog <| Dialog.UpdateAndClose - <| Msg.CreatePayment data.name data.cost data.date data.category data.frequency + <| Msg.CreatePayment (String.trim data.name) data.cost data.date data.category data.frequency Nothing -> Msg.Dialog <| Dialog.Update <| DialogMsg.AddPaymentMsg categories paymentCategories <| Form.Submit |