From d13c145b9732e35d84e2d9ce6c63f5e3cb51c075 Mon Sep 17 00:00:00 2001 From: Axel Angel Date: Wed, 18 Sep 2013 19:56:41 +0200 Subject: [PATCH 1/3] Add checkboxesField{,List} fields (based on multiSelectField{,List}) squashed: - Attrs are applied to checkboxes in checkBoxField - Fix checkboxesField{,List} attrs are applied to input instead of span - Fix checkboxesField{,List} attribute checked --- yesod-form/Yesod/Form/Fields.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/yesod-form/Yesod/Form/Fields.hs b/yesod-form/Yesod/Form/Fields.hs index 5c16d7eb..75f9cb97 100644 --- a/yesod-form/Yesod/Form/Fields.hs +++ b/yesod-form/Yesod/Form/Fields.hs @@ -388,6 +388,29 @@ radioFieldList :: (Eq a, RenderMessage site FormMessage, RenderMessage site msg) -> Field (HandlerT site IO) a radioFieldList = radioField . optionsPairs +checkboxesFieldList :: (Eq a, RenderMessage site FormMessage, RenderMessage site msg) => [(msg, a)] + -> Field (HandlerT site IO) [a] +checkboxesFieldList = checkboxesField . optionsPairs + +checkboxesField :: (Eq a, RenderMessage site FormMessage) + => HandlerT site IO (OptionList a) + -> Field (HandlerT site IO) [a] +checkboxesField ioptlist = (multiSelectField ioptlist) + { fieldView = + \theId name attrs val isReq -> do + opts <- fmap olOptions $ handlerToWidget ioptlist + let optselected (Left _) _ = False + optselected (Right vals) opt = (optionInternalValue opt) `elem` vals + let selOpts = map (id &&& (optselected val)) opts + [whamlet| + + $forall (opt, optsel) <- selOpts +