Commits

dp wiz committed 2f7e456

Show field errors as group class

Comments (0)

Files changed (2)

Layout/Bootstrap/Forms.hs

 
                       withErrors = map (\field -> case err (title field) of
                                                       [] -> field
-                                                      fe -> field { help = "Error" })
+                                                      fe -> field { errors = True })
 
                       extraFields fs = forM_ fs (\f -> H.input
                                                        ! A.type_ "hidden"

Layout/Bootstrap/Widgets.hs

                    } deriving (Show)
 
 instance ToHtml Input where
-    toHtml i = H.div ! A.class_ "control-group" $ do
+    toHtml i = H.div ! A.class_ groupLabels $ do
                    H.label ! A.class_ "control-label" ! A.for id $ toHtml (title i)
                    H.div ! A.class_ "controls" $ do
                        H.input ! A.type_ "text" ! A.id id ! A.name (toValue name) ! A.placeholder (toValue $ placeholder i) ! A.class_ "input-xlarge"
                where
                    name = T.toLower (title i)
                    id = toValue ("id_" ++ T.unpack name)
+                   groupLabels = toValue . unwords $ ["control-group"] ++ (if errors i then ["error"] else [])
     {-# INLINE toHtml #-}
 
 -- | Text field with only name provided. Good to start with record overrides. Needs 'toHtml' when inserted into 'Html' tree.