From 79dd6af899fbaf7c413d7fd864f5716cbdf544e5 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Fri, 7 Jun 2024 15:53:01 +0200 Subject: require strings to be non-empty --- frontend/app/Form/Input.hs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'frontend/app') diff --git a/frontend/app/Form/Input.hs b/frontend/app/Form/Input.hs index 80044ec..e43651c 100644 --- a/frontend/app/Form/Input.hs +++ b/frontend/app/Form/Input.hs @@ -10,18 +10,26 @@ import Miso.String (fromMisoString, toMisoString) input :: String -> Form T.Text T.Text input label = - Form - { view = \i -> - [ div_ [] $ - [ label_ [] $ - [ text (toMisoString label), - input_ - [ type_ "text", - value_ (toMisoString i), - onInput fromMisoString + let parse :: T.Text -> Either String T.Text + parse i = + let i' = T.strip i + in if T.null i' then Left "required" else Right i' + in Form + { view = \i -> + [ div_ [] $ + [ label_ [] $ + [ text (toMisoString label), + div_ [] $ + [ input_ + [ type_ "text", + value_ (toMisoString i), + onInput fromMisoString + ], + div_ [] $ + [either (text . toMisoString) (\_ -> text "") (parse i)] + ] ] ] - ] - ], - fill = \i -> Right i - } + ], + fill = parse + } -- cgit v1.2.3