0 | module Web.MVC.Controller.Validation
3 | import Text.HTML.Extra
5 | import Web.MVC.Controller
9 | parameters {0 i : Type}
10 | {auto cst : Cast i DomID}
11 | {auto env : ValEnv i}
16 | validateState : (s -> Either String t) -> i -> s -> Cmd e
17 | validateState f u = elemChild (env.msgID u) . Text . either id (const "") . f
22 | valTextInput : (String -> Either String t) -> i -> Controller String String
23 | valTextInput rd u = displayEv (validate (inpRef $
env.inputID u) . rd)
29 | validated : Editor i s e n -> Editor i s e n
31 | E (\u,v => ed.ctrl u v <+> map (validateState ed.stToNew u) get)
32 | (\u,s => validated u (ed.view u s))
33 | (\u,s => validateState ed.stToNew u s <+> ed.init u s)
38 | checkVal : (String -> Either String t) -> String -> Either String t
42 | Left x => if trim s == "" then Left env.mandatory else Left x
59 | -> (tpe : InputType)
60 | -> (stToNew : String -> Either String new)
61 | -> (disp : Maybe new -> String)
62 | -> Editor i String String new
64 | let g := checkVal f in E (valTextInput g) (vinp c tpe) noInit g