aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Form/Input.hs
blob: 99fd8217de67d63e21b6a9931b6370f1c18128e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Form.Input
  ( input,
  )
where

import Form.Internal
import Miso
import Miso.String (MisoString, null, strip)

input :: MisoString -> Form MisoString MisoString
input label =
  let parse :: MisoString -> Either MisoString MisoString
      parse i =
        let i' = strip i
         in if Miso.String.null i' then Left "required" else Right i'
   in Form
        { view = \i ->
            [ div_ [] $
                [ label_ [] $
                    [ text label,
                      div_ [] $
                        [ input_
                            [ type_ "text",
                              value_ i,
                              onInput id
                            ],
                          div_ [] $
                            [either text (\_ -> text "") (parse i)]
                        ]
                    ]
                ]
            ],
          fill = parse
        }