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 ...@@ -7,7 +7,7 @@ import DateExtra
import Color.Convert import Color.Convert
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (onInput, onClick) import Html.Events exposing (onInput, onClick, onSubmit)
import Lifechart.Model exposing (..) import Lifechart.Model exposing (..)
import Lifechart.Serializer as Serializer import Lifechart.Serializer as Serializer
...@@ -56,7 +56,7 @@ controls model = ...@@ -56,7 +56,7 @@ controls model =
[ [ h1 [ class "text-xs-center mb-1" ] [ text "Spend your time wisely." ] ] [ [ 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." ] ] , [ div [ class "text-xs-center text-muted mb-1" ] [ text "This will either inspire you or terrify you - hopefully the former." ] ]
, links model , links model
, form model , config model
, metrics model , metrics model
, events model , events model
, footer , footer
...@@ -77,20 +77,18 @@ links model = ...@@ -77,20 +77,18 @@ links model =
] ]
form : Model -> List (Html Msg) config : Model -> List (Html Msg)
form model = config model =
[ div [ class "row form-group" ] [ div [ class "row form-group" ]
[ label [ class "col-xs-4 col-form-label col-form-label-lg" ] [ text "Date of Birth" ] [ label [ class "col-xs-4 col-form-label col-form-label-lg" ] [ text "Date of Birth" ]
, div [ class "col-xs-8" ] , div [ class "col-xs-8" ]
[ input [ input
[ class "form-control form-control-lg" (List.append dateInputAttributes
, type_ "date" [ class "form-control form-control-lg"
, required True , value model.dateOfBirthString
, placeholder "YYYY-MM-DD" , onInput NewDateOfBirth
, pattern "[1-2]\\d{3}-[0-1]\\d-[0-3]\\d" ]
, value model.dateOfBirthString )
, onInput NewDateOfBirth
]
[] []
] ]
] ]
...@@ -119,17 +117,17 @@ newEvent model = ...@@ -119,17 +117,17 @@ newEvent model =
else else
" hidden-xs-up" " hidden-xs-up"
form = inputs =
[ div [ class "row form-group" ] [ div [ class "row form-group" ]
[ div [ class "col-xs-6" ] [ div [ class "col-xs-6" ]
[ div [ class "input-group" ] [ div [ class "input-group" ]
[ span [ class "input-group-addon" ] [ text "From" ] [ span [ class "input-group-addon" ] [ text "From" ]
, input , input
[ class "form-control" (List.append dateInputAttributes
, type_ "date" [ class "form-control"
, required True , onInput (UpdateNewEvent EventFrom)
, onInput (UpdateNewEvent EventFrom) ]
] )
[] []
] ]
] ]
...@@ -137,11 +135,11 @@ newEvent model = ...@@ -137,11 +135,11 @@ newEvent model =
[ div [ class "input-group" ] [ div [ class "input-group" ]
[ span [ class "input-group-addon" ] [ text "To" ] [ span [ class "input-group-addon" ] [ text "To" ]
, input , input
[ class "form-control" (List.append dateInputAttributes
, type_ "date" [ class "form-control"
, required True , onInput (UpdateNewEvent EventTo)
, onInput (UpdateNewEvent EventTo) ]
] )
[] []
] ]
] ]
...@@ -177,7 +175,6 @@ newEvent model = ...@@ -177,7 +175,6 @@ newEvent model =
[ class "btn btn-primary" [ class "btn btn-primary"
, type_ "submit" , type_ "submit"
, value "Add" , value "Add"
, onClick SaveNewEvent
] ]
[] []
] ]
...@@ -195,7 +192,9 @@ newEvent model = ...@@ -195,7 +192,9 @@ newEvent model =
[ text "Add event" ] [ 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 = ...@@ -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 -> String
weeksLeft model = weeksLeft model =
let let
......
- validate form for add event (non-empty label + dates)
- UI to edit events - UI to edit events
- hideUnproductiveYears : Bool - hideUnproductiveYears : Bool
https://www.reddit.com/r/GetMotivated/comments/1vyf9r/made_for_myself_thought_of_you_weeks_left/cexas8u 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