diff options
Diffstat (limited to 'frontend/app/Form')
-rw-r--r-- | frontend/app/Form/Input.hs | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/frontend/app/Form/Input.hs b/frontend/app/Form/Input.hs index 99fd821..7619326 100644 --- a/frontend/app/Form/Input.hs +++ b/frontend/app/Form/Input.hs @@ -1,14 +1,41 @@ module Form.Input - ( input, + ( inputText, + inputNumber, ) where import Form.Internal import Miso -import Miso.String (MisoString, null, strip) +import Miso.String (MisoString, fromMisoString, null, strip, toMisoString) -input :: MisoString -> Form MisoString MisoString -input label = +inputNumber :: MisoString -> Form MisoString Double +inputNumber label = + let parse :: MisoString -> Either MisoString Double + parse i = + let i' = strip i + in if Miso.String.null i' then Left "required" else Right (read (fromMisoString i')) + in Form + { view = \i -> + [ div_ [] $ + [ label_ [] $ + [ text label, + div_ [] $ + [ input_ + [ type_ "number", + value_ (toMisoString (show i)), + onInput id + ], + div_ [] $ + [either text (\_ -> text "") (parse i)] + ] + ] + ] + ], + fill = parse + } + +inputText :: MisoString -> Form MisoString MisoString +inputText label = let parse :: MisoString -> Either MisoString MisoString parse i = let i' = strip i |