Skip to content
Snippets Groups Projects
Verified Commit 06b1638d authored by jan.hamal.dvorak's avatar jan.hamal.dvorak
Browse files

Make Form exports more ergonomic

parent ea445ffd
No related branches found
No related tags found
No related merge requests found
...@@ -31,10 +31,11 @@ module Hikaru.Form ...@@ -31,10 +31,11 @@ module Hikaru.Form
, multiSelectField' , multiSelectField'
, opt , opt
, req , req
, whenChecking
, fieldShouldCheck
, fieldValue
, addNote , addNote
, addAttribute , addAttribute
, fieldCheck
, fieldValue
, hasErrors , hasErrors
) )
where where
...@@ -433,17 +434,11 @@ where ...@@ -433,17 +434,11 @@ where
-- --
req :: (Monad m) => l -> FieldT l a m () req :: (Monad m) => l -> FieldT l a m ()
req label = do req label = do
shouldCheck <- fieldCheck whenChecking do
value <- fieldValue
if shouldCheck case value of
then do Nothing -> addNote $ NoteError label
value <- fieldValue Just _v -> return ()
case value of
Nothing -> addNote $ NoteError label
Just _v -> return ()
else do
return ()
-- | -- |
...@@ -466,8 +461,20 @@ where ...@@ -466,8 +461,20 @@ where
-- | -- |
-- TODO -- TODO
-- --
fieldCheck :: (Monad m) => FieldT l a m Bool whenChecking :: (Monad m) => FieldT l a m b -> FieldT l a m ()
fieldCheck = FieldT (fst <$> ask) whenChecking checkField = do
check <- fieldShouldCheck
if check
then checkField >> return ()
else return ()
-- |
-- TODO
--
fieldShouldCheck :: (Monad m) => FieldT l a m Bool
fieldShouldCheck = FieldT (fst <$> ask)
-- | -- |
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment