diff options
author | Joris | 2017-03-24 09:21:04 +0000 |
---|---|---|
committer | Joris | 2017-03-24 09:21:04 +0000 |
commit | cfca18262c1ff48dcb683ddab7d03cf8e55573ff (patch) | |
tree | 8a438430cee7411259fc395d8f3898488e85d750 /src/client/elm/Validation.elm | |
parent | 293eb8295162bf0a038f488237db9c9d1316c04d (diff) | |
download | budget-cfca18262c1ff48dcb683ddab7d03cf8e55573ff.tar.gz budget-cfca18262c1ff48dcb683ddab7d03cf8e55573ff.tar.bz2 budget-cfca18262c1ff48dcb683ddab7d03cf8e55573ff.zip |
Features/categories
Diffstat (limited to 'src/client/elm/Validation.elm')
-rw-r--r-- | src/client/elm/Validation.elm | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/client/elm/Validation.elm b/src/client/elm/Validation.elm index 1729daa..18b3934 100644 --- a/src/client/elm/Validation.elm +++ b/src/client/elm/Validation.elm @@ -1,14 +1,18 @@ module Validation exposing ( date + , category ) -import String exposing (toInt, split) import Date exposing (Date) -import Date.Extra.Create exposing (dateFromFields) import Date.Extra.Core exposing (intToMonth) +import Date.Extra.Create exposing (dateFromFields) +import Dict +import String exposing (toInt, split) import Form.Validate as Validate exposing (..) +import Model.Category exposing (Categories, CategoryId) + date : Validation String Date date = customValidation string (\str -> @@ -20,3 +24,15 @@ date = _ -> Err (customError "InvalidDate") _ -> Err (customError "InvalidDate") ) + +category : Categories -> Validation String CategoryId +category categories = + customValidation string (\str -> + case toInt str of + Ok category -> + if List.member category (Dict.keys categories) + then Ok category + else Err (customError "InvalidCategory") + Err _ -> + Err (customError "InvalidCategory") + ) |