diff options
Diffstat (limited to 'frontend/app/Form')
-rw-r--r-- | frontend/app/Form/Input.hs | 19 | ||||
-rw-r--r-- | frontend/app/Form/Internal.hs | 8 |
2 files changed, 13 insertions, 14 deletions
diff --git a/frontend/app/Form/Input.hs b/frontend/app/Form/Input.hs index e43651c..99fd821 100644 --- a/frontend/app/Form/Input.hs +++ b/frontend/app/Form/Input.hs @@ -3,30 +3,29 @@ module Form.Input ) where -import Data.Text qualified as T import Form.Internal import Miso -import Miso.String (fromMisoString, toMisoString) +import Miso.String (MisoString, null, strip) -input :: String -> Form T.Text T.Text +input :: MisoString -> Form MisoString MisoString input label = - let parse :: T.Text -> Either String T.Text + let parse :: MisoString -> Either MisoString MisoString parse i = - let i' = T.strip i - in if T.null i' then Left "required" else Right i' + let i' = strip i + in if Miso.String.null i' then Left "required" else Right i' in Form { view = \i -> [ div_ [] $ [ label_ [] $ - [ text (toMisoString label), + [ text label, div_ [] $ [ input_ [ type_ "text", - value_ (toMisoString i), - onInput fromMisoString + value_ i, + onInput id ], div_ [] $ - [either (text . toMisoString) (\_ -> text "") (parse i)] + [either text (\_ -> text "") (parse i)] ] ] ] diff --git a/frontend/app/Form/Internal.hs b/frontend/app/Form/Internal.hs index 2274c63..35d59e7 100644 --- a/frontend/app/Form/Internal.hs +++ b/frontend/app/Form/Internal.hs @@ -6,12 +6,12 @@ module Form.Internal ) where -import Data.Text qualified as T import Miso +import Miso.String (MisoString, null, strip) data Form i o = Form { view :: i -> [View i], - fill :: i -> Either String o + fill :: i -> Either MisoString o } instance Functor (Form i) where @@ -63,8 +63,8 @@ runForm form i = class IsEmpty i where isEmpty :: i -> Bool -instance IsEmpty T.Text where - isEmpty = T.null . T.strip +instance IsEmpty MisoString where + isEmpty = Miso.String.null . strip optional :: (IsEmpty i) => Form i o -> Form i (Maybe o) optional form = |