summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-01-02 10:20:45 +0100
committerYorhel <git@yorhel.nl>2020-01-02 10:20:47 +0100
commit651649b642d0e07052625b83fbbe2fdbb6ee1f11 (patch)
treec3b24d524e6db9dc0376b65b646d304fd385c046
parent65b5997873c331321f9b0594cd2477ffc1242751 (diff)
ulist: Add extra client-side validation for the date editing
Because apparently it's possible to input dates that don't match the 'pattern' attribute and still validate according to HTML5.
-rw-r--r--elm/UList/DateEdit.elm9
1 files changed, 8 insertions, 1 deletions
diff --git a/elm/UList/DateEdit.elm b/elm/UList/DateEdit.elm
index 5ec01edd..a9a94960 100644
--- a/elm/UList/DateEdit.elm
+++ b/elm/UList/DateEdit.elm
@@ -6,6 +6,7 @@ import Html.Events exposing (..)
import Task
import Process
import Browser
+import Regex
import Lib.Html exposing (..)
import Lib.Api as Api
import Gen.Api as GApi
@@ -45,12 +46,18 @@ type Msg
| Save Int
| Saved GApi.Response
+isDate : String -> Bool
+isDate s
+ = Regex.fromString "^(?:19[7-9][0-9]|20[0-9][0-9])-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])$"
+ |> Maybe.map (\r -> Regex.contains r s) |> Maybe.withDefault True
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
Show -> ({ model | visible = True }, Cmd.none)
- Val s b -> ({ model | valid = b, val = s, debnum = model.debnum + 1 }, Task.perform (\_ -> Save (model.debnum+1)) <| Process.sleep 300)
+ Val s b ->
+ ({ model | val = s, debnum = model.debnum + 1, valid = b && isDate s }
+ , Task.perform (\_ -> Save (model.debnum+1)) <| Process.sleep 300)
Save n ->
if n /= model.debnum || model.val == model.flags.date || not model.valid