From 3c12e3678f40c823cdad1901688bb5352517f715 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Fri, 8 Jan 2021 00:03:14 +0100 Subject: [PATCH] Allow to search for `*` in custom date fields This requires to pass the raw input through to the caller. Closes: #550 --- .../src/main/elm/Comp/CustomFieldInput.elm | 18 +++++++++++++----- .../webapp/src/main/elm/Comp/DatePicker.elm | 8 +++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/webapp/src/main/elm/Comp/CustomFieldInput.elm b/modules/webapp/src/main/elm/Comp/CustomFieldInput.elm index 21dfbbf5..dd19a050 100644 --- a/modules/webapp/src/main/elm/Comp/CustomFieldInput.elm +++ b/modules/webapp/src/main/elm/Comp/CustomFieldInput.elm @@ -266,6 +266,13 @@ update1 forSearch msg model = DatePicker.None -> ( old, NoResult ) + DatePicker.FailedInput (DatePicker.Invalid str) -> + if forSearch && hasWildCards str then + ( Nothing, Value str ) + + else + ( old, NoResult ) + DatePicker.FailedInput _ -> ( old, NoResult ) @@ -289,11 +296,7 @@ updateFloatModel : -> (String -> String) -> ( FloatModel, FieldResult ) updateFloatModel forSearch msg parse normalize = - let - hasWildCards = - String.startsWith "*" msg || String.endsWith "*" msg - in - if forSearch && hasWildCards then + if forSearch && hasWildCards msg then ( { input = normalize msg , result = Ok 0 } @@ -317,6 +320,11 @@ updateFloatModel forSearch msg parse normalize = ) +hasWildCards : String -> Bool +hasWildCards msg = + String.startsWith "*" msg || String.endsWith "*" msg + + --- View diff --git a/modules/webapp/src/main/elm/Comp/DatePicker.elm b/modules/webapp/src/main/elm/Comp/DatePicker.elm index f8c0ad3f..a983aa47 100644 --- a/modules/webapp/src/main/elm/Comp/DatePicker.elm +++ b/modules/webapp/src/main/elm/Comp/DatePicker.elm @@ -39,7 +39,13 @@ defaultSettings = ds = DatePicker.defaultSettings in - { ds | changeYear = DatePicker.from 2010 } + { ds + | changeYear = DatePicker.from 2010 + , parser = + \str -> + ds.parser str + |> Result.mapError (\_ -> str) + } update : Settings -> Msg -> DatePicker -> ( DatePicker, DateEvent )