simple-form 0.2 → 0.3
raw patch · 6 files changed
+43/−6 lines, 6 files
Files
- SimpleForm.hs +19/−1
- SimpleForm/Combined.hs +7/−0
- SimpleForm/Digestive/Combined.hs +8/−4
- SimpleForm/Digestive/Internal.hs +3/−0
- SimpleForm/Render/XHTML5.hs +5/−0
- simple-form.cabal +1/−1
SimpleForm.hs view
@@ -43,6 +43,7 @@ select, multi_select, radio_buttons,+ buttons, checkboxes, -- * Helpers input_tag,@@ -205,7 +206,7 @@ wdef = time instance (Integral a, Show a) => DefaultWidget (Ratio a) where- wdef = number+ wdef = number . fmap (\x -> realToFrac x :: Double) instance (DefaultWidget a, DefaultWidget b) => DefaultWidget (a, b) where wdef v u n opt = wdef (fmap fst v) u n opt `mappend` wdef (fmap snd v) u n opt@@ -446,6 +447,23 @@ mkChecked (Just value == v) $ input_tag n (Just value) (T.pack "radio") [] opt HTML.toHtml label+ formatCollection f+ | length collection == 1 && fst (head collection) == mempty =+ f (snd $ head collection)+ | otherwise =+ (`map` collection) $ \(group, subCollection) ->+ HTML.fieldset $ do+ HTML.legend $ HTML.toHtml group+ mconcat (f subCollection)++buttons :: GroupedCollection -> Widget Text+buttons collection _ u n opt =+ MultiInput $ formatCollection $ map go+ where+ go (value, label) =+ let SelfLabelInput html =+ button (Just value) u n (opt {label = Just $ Label label})+ in html formatCollection f | length collection == 1 && fst (head collection) == mempty = f (snd $ head collection)
SimpleForm/Combined.hs view
@@ -43,6 +43,7 @@ select, multi_select, radio_buttons,+ buttons, checkboxes, -- * Helpers selectEnum,@@ -156,6 +157,12 @@ radio_buttons :: GroupedCollection' a -> (Widget Text, Validation a) radio_buttons collection = ( SimpleForm.radio_buttons (Validation.viewGroupedCollection collection),+ Validation.includes collection+ )++buttons :: GroupedCollection' a -> (Widget Text, Validation a)+buttons collection = (+ SimpleForm.buttons (Validation.viewGroupedCollection collection), Validation.includes collection )
SimpleForm/Digestive/Combined.hs view
@@ -3,6 +3,7 @@ -- The Combined module both renders to 'Html' and also parses input. module SimpleForm.Digestive.Combined ( SimpleForm,+ SimpleForm', postSimpleForm, getSimpleForm, simpleForm',@@ -37,14 +38,17 @@ import SimpleForm.Render +-- | Convenience type synonym for combined forms+type SimpleForm' m a = SimpleForm a (Form Html m a)+ -- | Render a 'SimpleForm' to 'Html' -- -- This produces the contents of the form, but you must still wrap it in -- the actual \<form\> element. getSimpleForm :: (Monad m) => Renderer- -> Maybe a -- ^ Default values for the form- -> SimpleForm a (Form Html m a) -- ^ The simple form to render+ -> Maybe a -- ^ Default values for the form+ -> SimpleForm' m a -- ^ The simple form to render -> m Html getSimpleForm render val form = do view <- getForm T.empty initialForm@@ -62,8 +66,8 @@ -- the actual \<form\> element. postSimpleForm :: (Monad m) => Renderer- -> m (Env m) -- ^ The digestive-functors input environment- -> SimpleForm a (Form Html m a) -- ^ The simple form to render+ -> m (Env m) -- ^ The digestive-functors input environment+ -> SimpleForm' m a -- ^ The simple form to render -> m (Html, Maybe a) postSimpleForm render env form = do env' <- env
SimpleForm/Digestive/Internal.hs view
@@ -70,9 +70,12 @@ render $ renderOptions (maybe Nothing sel env) unparsed (pathToText apth) w errors $ opt {+ label = defaultLabel (label opt), disabled = disabled opt || Disabled `elem` metadata } where+ defaultLabel (Just DefaultLabel) = Just $ Label $ humanize n+ defaultLabel x = x apth = case absolutePath n view of (p:ps) | T.null p -> ps
SimpleForm/Render/XHTML5.hs view
@@ -16,6 +16,7 @@ render opt@(RenderOptions { name = n, widgetHtml = Input whtml,+ errors = errors, options = InputOptions { label = lbl, disabled = d,@@ -25,6 +26,7 @@ } }) = applyAttrs (+ maybeCons (not $ null errors) (T.pack "class", T.pack "error") $ maybeCons d (T.pack "class", T.pack "disabled") $ maybeCons r (T.pack "class", T.pack "required") []@@ -44,6 +46,7 @@ } }) = applyAttrs (+ maybeCons (not $ null errors) (T.pack "class", T.pack "error") $ maybeCons d (T.pack "class", T.pack "disabled") $ maybeCons r (T.pack "class", T.pack "required") []@@ -56,6 +59,7 @@ render opt@(RenderOptions { name = n, widgetHtml = MultiInput whtml,+ errors = errors, options = InputOptions { label = lbl, disabled = d,@@ -65,6 +69,7 @@ } }) = applyAttrs (+ maybeCons (not $ null errors) (T.pack "class", T.pack "error") $ maybeCons d (T.pack "disabled", T.pack "disabled") $ maybeCons d (T.pack "class", T.pack "disabled") $ maybeCons r (T.pack "class", T.pack "required")
simple-form.cabal view
@@ -1,5 +1,5 @@ name: simple-form-version: 0.2+version: 0.3 cabal-version: >= 1.8 license: OtherLicense license-file: COPYING