Merge pull request #1775 from SupercedeTech/add-with-option-more-flexible-radio-inputs
Add withRadioField a more flexible radio option renderer
This commit is contained in:
commit
65adf9ba72
@ -1,5 +1,9 @@
|
|||||||
# ChangeLog for yesod-form
|
# 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
|
## 1.7.1
|
||||||
|
|
||||||
* Added `colorField` for creating a html color field (`<input type="color">`) [#1748](https://github.com/yesodweb/yesod/pull/1748)
|
* Added `colorField` for creating a html color field (`<input type="color">`) [#1748](https://github.com/yesodweb/yesod/pull/1748)
|
||||||
|
|||||||
@ -49,6 +49,7 @@ module Yesod.Form.Fields
|
|||||||
, selectFieldListGrouped
|
, selectFieldListGrouped
|
||||||
, radioField
|
, radioField
|
||||||
, radioFieldList
|
, radioFieldList
|
||||||
|
, withRadioField
|
||||||
, checkboxesField
|
, checkboxesField
|
||||||
, checkboxesFieldList
|
, checkboxesFieldList
|
||||||
, multiSelectField
|
, multiSelectField
|
||||||
@ -530,26 +531,50 @@ checkboxesField ioptlist = (multiSelectField ioptlist)
|
|||||||
radioField :: (Eq a, RenderMessage site FormMessage)
|
radioField :: (Eq a, RenderMessage site FormMessage)
|
||||||
=> HandlerFor site (OptionList a)
|
=> HandlerFor site (OptionList a)
|
||||||
-> Field (HandlerFor site) a
|
-> Field (HandlerFor site) a
|
||||||
radioField = selectFieldHelper
|
radioField = withRadioField
|
||||||
(\theId _name _attrs inside -> [whamlet|
|
(\theId optionWidget -> [whamlet|
|
||||||
$newline never
|
|
||||||
<div ##{theId}>^{inside}
|
|
||||||
|])
|
|
||||||
(\theId name isSel -> [whamlet|
|
|
||||||
$newline never
|
$newline never
|
||||||
<label .radio for=#{theId}-none>
|
<label .radio for=#{theId}-none>
|
||||||
<div>
|
<div>
|
||||||
<input id=#{theId}-none type=radio name=#{name} value=none :isSel:checked>
|
^{optionWidget}
|
||||||
_{MsgSelectNone}
|
_{MsgSelectNone}
|
||||||
|])
|
|])
|
||||||
(\theId name attrs value isSel text -> [whamlet|
|
(\theId value _isSel text optionWidget -> [whamlet|
|
||||||
$newline never
|
$newline never
|
||||||
<label .radio for=#{theId}-#{value}>
|
<label .radio for=#{theId}-#{value}>
|
||||||
<div>
|
<div>
|
||||||
<input id=#{theId}-#{value} type=radio name=#{name} value=#{value} :isSel:checked *{attrs}>
|
^{optionWidget}
|
||||||
\#{text}
|
\#{text}
|
||||||
|])
|
|])
|
||||||
Nothing
|
|
||||||
|
|
||||||
|
-- | Allows the user to place the option radio widget somewhere in
|
||||||
|
-- the template.
|
||||||
|
-- For example: If you want a table of radio options to select.
|
||||||
|
-- 'radioField' is an example on how to use this function.
|
||||||
|
--
|
||||||
|
-- @since 1.7.2
|
||||||
|
withRadioField :: (Eq a, RenderMessage site FormMessage)
|
||||||
|
=> (Text -> WidgetFor site ()-> WidgetFor site ()) -- ^ nothing case for mopt
|
||||||
|
-> (Text -> Text -> Bool -> Text -> WidgetFor site () -> WidgetFor site ()) -- ^ cases for values
|
||||||
|
-> HandlerFor site (OptionList a)
|
||||||
|
-> Field (HandlerFor site) a
|
||||||
|
withRadioField nothingFun optFun =
|
||||||
|
selectFieldHelper outside onOpt inside Nothing
|
||||||
|
where
|
||||||
|
outside theId _name _attrs inside' = [whamlet|
|
||||||
|
$newline never
|
||||||
|
<div ##{theId}>^{inside'}
|
||||||
|
|]
|
||||||
|
onOpt theId name isSel = nothingFun theId $ [whamlet|
|
||||||
|
$newline never
|
||||||
|
<input id=#{theId}-none type=radio name=#{name} value=none :isSel:checked>
|
||||||
|
|]
|
||||||
|
inside theId name attrs value isSel display =
|
||||||
|
optFun theId value isSel display [whamlet|
|
||||||
|
<input id=#{theId}-#{(value)} type=radio name=#{name} value=#{(value)} :isSel:checked *{attrs}>
|
||||||
|
|]
|
||||||
|
|
||||||
|
|
||||||
-- | Creates a group of radio buttons to answer the question given in the message. Radio buttons are used to allow differentiating between an empty response (@Nothing@) and a no response (@Just False@). Consider using the simpler 'checkBoxField' if you don't need to make this distinction.
|
-- | Creates a group of radio buttons to answer the question given in the message. Radio buttons are used to allow differentiating between an empty response (@Nothing@) and a no response (@Just False@). Consider using the simpler 'checkBoxField' if you don't need to make this distinction.
|
||||||
--
|
--
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
cabal-version: >= 1.10
|
cabal-version: >= 1.10
|
||||||
name: yesod-form
|
name: yesod-form
|
||||||
version: 1.7.1
|
version: 1.7.2
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user