diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-06-07 15:53:01 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-06-07 15:53:01 +0200 |
commit | 79dd6af899fbaf7c413d7fd864f5716cbdf544e5 (patch) | |
tree | e796a2fe9e1ceabaaff43ab651f73183948de8c8 /frontend | |
parent | 378e007141c699945080bbf944aeef4abf67d75c (diff) |
require strings to be non-empty
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/app/Form/Input.hs | 34 |
1 files changed, 21 insertions, 13 deletions
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 + } |