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

Adjust the FormNote signature

parent 6245f978
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ module Hikaru.Form ...@@ -14,6 +14,7 @@ module Hikaru.Form
( MonadCsrf(..) ( MonadCsrf(..)
, View(..) , View(..)
, FormNote(..) , FormNote(..)
, NoteLevel(..)
, Form , Form
, FieldT , FieldT
, newForm , newForm
...@@ -50,9 +51,7 @@ where ...@@ -50,9 +51,7 @@ where
import Data.Text (Text, strip) import Data.Text (Text, strip)
import Hikaru.Action import Hikaru.Action
import Hikaru.CSRF import Hikaru.CSRF
import Hikaru.Localize
import Hikaru.Types import Hikaru.Types
import Lucid
-- Form Types -------------------------------------------------------------- -- Form Types --------------------------------------------------------------
...@@ -111,24 +110,25 @@ where ...@@ -111,24 +110,25 @@ where
mempty = FormFields [] [] mempty = FormFields [] []
-- |
-- TODO
--
data FormNote l data FormNote l
= NoteError = FormNote
{ noteLabel :: l { noteLevel :: NoteLevel
} , noteLabel :: l
| NoteNeutral
{ noteLabel :: l
}
| NoteSuccess
{ noteLabel :: l
} }
deriving (Eq, Ord) deriving (Eq, Ord)
instance (ToHtml l) => ToHtml (FormNote l) where
toHtml = toHtml . noteLabel
toHtmlRaw = toHtmlRaw . noteLabel
instance (Localized l) => Localized (FormNote l) where -- |
localize lang = localize lang . noteLabel -- TODO
--
data NoteLevel
= NoteError
| NoteNeutral
| NoteSuccess
deriving (Eq, Ord)
newtype FormT l m a newtype FormT l m a
...@@ -274,7 +274,7 @@ where ...@@ -274,7 +274,7 @@ where
let view = HiddenField { viewName = name' let view = HiddenField { viewName = name'
, viewValue = Just token , viewValue = Just token
, viewNotes = if envCheck && not valid , viewNotes = if envCheck && not valid
then [NoteError msg] then [FormNote NoteError msg]
else [] else []
, viewAttrs = [] , viewAttrs = []
} }
...@@ -483,7 +483,7 @@ where ...@@ -483,7 +483,7 @@ where
whenChecking do whenChecking do
value <- fieldValue value <- fieldValue
case value of case value of
Nothing -> addNote $ NoteError label Nothing -> addNote $ FormNote NoteError label
Just _v -> return () Just _v -> return ()
...@@ -562,8 +562,8 @@ where ...@@ -562,8 +562,8 @@ where
isErrorNote :: FormNote l -> Bool isErrorNote :: FormNote l -> Bool
isErrorNote NoteError{} = True isErrorNote (FormNote NoteError _) = True
isErrorNote _ = False isErrorNote _else = False
formParamMaybe :: (Monad m, FromParam a) => Text -> FormT l m (Maybe a) formParamMaybe :: (Monad m, FromParam a) => Text -> FormT l m (Maybe a)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment