Commit 1f4c555c authored by Cédric F.'s avatar Cédric F.

Validate form before adding event

parent 4669324a
Pipeline #5385441 passed with stage
in 1 minute and 34 seconds
......@@ -7,7 +7,7 @@ import DateExtra
import Color.Convert
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput, onClick)
import Html.Events exposing (onInput, onClick, onSubmit)
import Lifechart.Model exposing (..)
import Lifechart.Serializer as Serializer
......@@ -56,7 +56,7 @@ controls model =
[ [ h1 [ class "text-xs-center mb-1" ] [ text "Spend your time wisely." ] ]
, [ div [ class "text-xs-center text-muted mb-1" ] [ text "This will either inspire you or terrify you - hopefully the former." ] ]
, links model
, form model
, config model
, metrics model
, events model
, footer
......@@ -77,20 +77,18 @@ links model =
]
form : Model -> List (Html Msg)
form model =
config : Model -> List (Html Msg)
config model =
[ div [ class "row form-group" ]
[ label [ class "col-xs-4 col-form-label col-form-label-lg" ] [ text "Date of Birth" ]
, div [ class "col-xs-8" ]
[ input
(List.append dateInputAttributes
[ class "form-control form-control-lg"
, type_ "date"
, required True
, placeholder "YYYY-MM-DD"
, pattern "[1-2]\\d{3}-[0-1]\\d-[0-3]\\d"
, value model.dateOfBirthString
, onInput NewDateOfBirth
]
)
[]
]
]
......@@ -119,17 +117,17 @@ newEvent model =
else
" hidden-xs-up"
form =
inputs =
[ div [ class "row form-group" ]
[ div [ class "col-xs-6" ]
[ div [ class "input-group" ]
[ span [ class "input-group-addon" ] [ text "From" ]
, input
(List.append dateInputAttributes
[ class "form-control"
, type_ "date"
, required True
, onInput (UpdateNewEvent EventFrom)
]
)
[]
]
]
......@@ -137,11 +135,11 @@ newEvent model =
[ div [ class "input-group" ]
[ span [ class "input-group-addon" ] [ text "To" ]
, input
(List.append dateInputAttributes
[ class "form-control"
, type_ "date"
, required True
, onInput (UpdateNewEvent EventTo)
]
)
[]
]
]
......@@ -177,7 +175,6 @@ newEvent model =
[ class "btn btn-primary"
, type_ "submit"
, value "Add"
, onClick SaveNewEvent
]
[]
]
......@@ -195,7 +192,9 @@ newEvent model =
[ text "Add event" ]
]
]
, li [ class <| "list-group-item" ++ visibility ] form
, li [ class <| "list-group-item" ++ visibility ]
[ Html.form [ onSubmit SaveNewEvent ] inputs
]
]
......@@ -303,6 +302,15 @@ footer =
]
dateInputAttributes : List (Attribute Msg)
dateInputAttributes =
[ type_ "date"
, required True
, placeholder "YYYY-MM-DD"
, pattern "[1-2]\\d{3}-[0-1]\\d-[0-3]\\d"
]
weeksLeft : Model -> String
weeksLeft model =
let
......
- validate form for add event (non-empty label + dates)
- UI to edit events
- hideUnproductiveYears : Bool
https://www.reddit.com/r/GetMotivated/comments/1vyf9r/made_for_myself_thought_of_you_weeks_left/cexas8u
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment