blob: 9bd6a09dbe84556b6f1fc71f7927f9e539b150fd (
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
37
|
module Dialog.Model exposing
( Model
, AddPayment
, init
, addPaymentInitial
)
import Form exposing (Form)
import Form.Field as Field exposing (Field)
import Form.Validate as Validate exposing (Validation)
import Model.Payment as Payment
type alias Model =
{ addPayment : Form String AddPayment
}
type alias AddPayment =
{ name : String
, cost : Int
, frequency : Payment.Frequency
}
init : Model
init =
{ addPayment = Form.initial [] addPaymentValidation
}
addPaymentInitial : Payment.Frequency -> List (String, Field)
addPaymentInitial frequency = [ ("frequency", Field.Radio (toString frequency)) ]
addPaymentValidation : Validation String AddPayment
addPaymentValidation =
Validate.form3 AddPayment
(Validate.get "name" (Validate.string `Validate.andThen` (Validate.nonEmpty)))
(Validate.get "cost" (Validate.int `Validate.andThen` (Validate.minInt 1)))
(Validate.get "frequency" Payment.validateFrequency)
|