blob: 7092fc47a67a5c8905018de88a78b6ffeb114c50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
module LoggedIn.Category.Model exposing
( Model
, AddCategory
, init
, initForm
, validation
)
import Date exposing (Date)
import Form exposing (Form)
import Form.Validate as Validate exposing (Validation)
import Validation
type alias Model =
{ addCategory : Form String AddCategory
}
type alias AddCategory =
{ amount : Int
, date : Date
}
init : Model
init =
{ addCategory = initForm
}
initForm : Form String AddCategory
initForm = Form.initial [] validation
validation : Validation String AddCategory
validation =
Validate.map2 AddCategory
(Validate.field "amount" (Validate.int |> Validate.andThen (Validate.minInt 1)))
(Validate.field "date" Validation.date)
|