From 25f83fb73d4a92832117a6b7b5ec57d696840afc Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Tue, 9 Aug 2022 15:54:46 +0200 Subject: [PATCH] Add withRadioField a more flexible radio option renderer This re-expresses radioField into the new more flexible function. Which gives an adhoc example on how to use it as well. This function passes the radio input to a callback function to let said function decide how it should be rendered. These changes allow you to make a radio table for example, for selecting some row. bump version number, add @since add note on radioField Update changelog --- yesod-form/ChangeLog.md | 4 +++ yesod-form/Yesod/Form/Fields.hs | 45 +++++++++++++++++++++++++-------- yesod-form/yesod-form.cabal | 2 +- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/yesod-form/ChangeLog.md b/yesod-form/ChangeLog.md index 9441bc049..ece605124 100644 --- a/yesod-form/ChangeLog.md +++ b/yesod-form/ChangeLog.md @@ -1,5 +1,9 @@ # ChangeLog for yesod-form +## 1.7.2 + +* Added `withRadioField` and re-express `radioField` into that. [#1775](https://github.com/yesodweb/yesod/pull/1775) + ## 1.7.1 * Added `colorField` for creating a html color field (``) [#1748](https://github.com/yesodweb/yesod/pull/1748) diff --git a/yesod-form/Yesod/Form/Fields.hs b/yesod-form/Yesod/Form/Fields.hs index f5812d736..7cbd34543 100644 --- a/yesod-form/Yesod/Form/Fields.hs +++ b/yesod-form/Yesod/Form/Fields.hs @@ -49,6 +49,7 @@ module Yesod.Form.Fields , selectFieldListGrouped , radioField , radioFieldList + , withRadioField , checkboxesField , checkboxesFieldList , multiSelectField @@ -530,26 +531,50 @@ checkboxesField ioptlist = (multiSelectField ioptlist) radioField :: (Eq a, RenderMessage site FormMessage) => HandlerFor site (OptionList a) -> Field (HandlerFor site) a -radioField = selectFieldHelper - (\theId _name _attrs inside -> [whamlet| -$newline never -
^{inside} -|]) - (\theId name isSel -> [whamlet| +radioField = withRadioField + (\theId optionWidget -> [whamlet| $newline never