diff --git a/yesod-form/ChangeLog.md b/yesod-form/ChangeLog.md index 3bd798ef6..32335a1f4 100644 --- a/yesod-form/ChangeLog.md +++ b/yesod-form/ChangeLog.md @@ -1,5 +1,9 @@ # ChangeLog for yesod-form +## 1.7.9 + +* Added `checkboxesField'` for creating checkbox in more correct way than original `checkboxesField` + Function `checkboxesField` marked as deprecated. [#1843](https://github.com/yesodweb/yesod/pull/1843) ## 1.7.8 diff --git a/yesod-form/Yesod/Form/Fields.hs b/yesod-form/Yesod/Form/Fields.hs index ab8583313..c08008af6 100644 --- a/yesod-form/Yesod/Form/Fields.hs +++ b/yesod-form/Yesod/Form/Fields.hs @@ -52,6 +52,7 @@ module Yesod.Form.Fields , radioFieldList , withRadioField , checkboxesField + , checkboxesField' , checkboxesFieldList , multiSelectField , multiSelectFieldList @@ -125,6 +126,7 @@ import Data.Monoid import Data.Char (isHexDigit) {-# DEPRECATED radioField "This function seems to have a bug (label could not be found with byLabel algorithm)" #-} +{-# DEPRECATED checkboxesField "This function seems to have a bug (label could not be found with byLabel algorithm)" #-} defaultFormMessage :: FormMessage -> Text defaultFormMessage = englishFormMessage @@ -533,6 +535,26 @@ checkboxesField ioptlist = (multiSelectField ioptlist) |] } +-- | Creates an input with @type="checkbox"@ for selecting multiple options. +checkboxesField' :: Eq a + => HandlerFor site (OptionList a) + -> Field (HandlerFor site) [a] +checkboxesField' ioptlist = (multiSelectField ioptlist) + { fieldView = + \theId name attrs val _isReq -> do + opts <- olOptions <$> handlerToWidget ioptlist + let optselected (Left _) _ = False + optselected (Right vals) opt = optionInternalValue opt `elem` vals + [whamlet| + + $forall opt <- opts + +