yesod-form 1.7.0 → 1.7.2
raw patch · 17 files changed
+82/−12 lines, 17 files
Files
- ChangeLog.md +8/−0
- Yesod/Form/Fields.hs +58/−10
- Yesod/Form/I18n/Chinese.hs +1/−0
- Yesod/Form/I18n/Czech.hs +1/−0
- Yesod/Form/I18n/Dutch.hs +1/−0
- Yesod/Form/I18n/English.hs +1/−0
- Yesod/Form/I18n/French.hs +1/−0
- Yesod/Form/I18n/German.hs +1/−0
- Yesod/Form/I18n/Japanese.hs +1/−0
- Yesod/Form/I18n/Korean.hs +1/−0
- Yesod/Form/I18n/Norwegian.hs +1/−0
- Yesod/Form/I18n/Portuguese.hs +1/−0
- Yesod/Form/I18n/Russian.hs +1/−0
- Yesod/Form/I18n/Spanish.hs +1/−0
- Yesod/Form/I18n/Swedish.hs +1/−0
- Yesod/Form/Types.hs +1/−0
- yesod-form.cabal +2/−2
ChangeLog.md view
@@ -1,5 +1,13 @@ # 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 (`<input type="color">`) [#1748](https://github.com/yesodweb/yesod/pull/1748)+ ## 1.7.0 * Extended `OptionList` by `OptionListGrouped` and implemented grouped select fields (`<select>` with `<optgroup>`) [#1722](https://github.com/yesodweb/yesod/pull/1722)
Yesod/Form/Fields.hs view
@@ -49,6 +49,7 @@ , selectFieldListGrouped , radioField , radioFieldList+ , withRadioField , checkboxesField , checkboxesFieldList , multiSelectField@@ -62,6 +63,7 @@ , optionsPairs , optionsPairsGrouped , optionsEnum+ , colorField ) where import Yesod.Form.Types@@ -117,6 +119,8 @@ import Data.Monoid #endif +import Data.Char (isHexDigit)+ defaultFormMessage :: FormMessage -> Text defaultFormMessage = englishFormMessage @@ -527,27 +531,51 @@ radioField :: (Eq a, RenderMessage site FormMessage) => HandlerFor site (OptionList a) -> Field (HandlerFor site) a-radioField = selectFieldHelper- (\theId _name _attrs inside -> [whamlet|-$newline never-<div ##{theId}>^{inside}-|])- (\theId name isSel -> [whamlet|+radioField = withRadioField+ (\theId optionWidget -> [whamlet| $newline never <label .radio for=#{theId}-none> <div>- <input id=#{theId}-none type=radio name=#{name} value=none :isSel:checked>+ ^{optionWidget} _{MsgSelectNone} |])- (\theId name attrs value isSel text -> [whamlet|+ (\theId value _isSel text optionWidget -> [whamlet| $newline never <label .radio for=#{theId}-#{value}> <div>- <input id=#{theId}-#{value} type=radio name=#{name} value=#{value} :isSel:checked *{attrs}>+ ^{optionWidget} \#{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. -- -- If this field is optional, the first radio button is labeled "\<None>", the second \"Yes" and the third \"No".@@ -948,3 +976,23 @@ -- The basic datastructure used is an 'Option', which combines a user-facing display value, the internal Haskell value being selected, and an external 'Text' stored as the @value@ in the form (used to map back to the internal value). A list of these, together with a function mapping from an external value back to a Haskell value, form an 'OptionList', which several of these functions take as an argument. -- -- Typically, you won't need to create an 'OptionList' directly and can instead make one with functions like 'optionsPairs' or 'optionsEnum'. Alternatively, you can use functions like 'selectFieldList', which use their @[(msg, a)]@ parameter to create an 'OptionList' themselves.++-- | Creates an input with @type="color"@.+-- The input value must be provided in hexadecimal format #rrggbb.+--+-- @since 1.7.1 +colorField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Text+colorField = Field+ { fieldParse = parseHelper $ \s ->+ if isHexColor $ unpack s then Right s+ else Left $ MsgInvalidHexColorFormat s+ , fieldView = \theId name attrs val _ -> [whamlet|+$newline never+<input ##{theId} name=#{name} *{attrs} type=color value=#{either id id val}>+|]+ , fieldEnctype = UrlEncoded+ }+ where+ isHexColor :: String -> Bool+ isHexColor ['#',a,b,c,d,e,f] = all isHexDigit [a,b,c,d,e,f]+ isHexColor _ = False
Yesod/Form/I18n/Chinese.hs view
@@ -24,3 +24,4 @@ chineseFormMessage MsgBoolYes = "是" chineseFormMessage MsgBoolNo = "否" chineseFormMessage MsgDelete = "删除?"+chineseFormMessage (MsgInvalidHexColorFormat t) = "颜色无效,必须为 #rrggbb 十六进制格式: " `mappend` t
Yesod/Form/I18n/Czech.hs view
@@ -24,3 +24,4 @@ czechFormMessage MsgBoolYes = "Ano" czechFormMessage MsgBoolNo = "Ne" czechFormMessage MsgDelete = "Smazat?"+czechFormMessage (MsgInvalidHexColorFormat t) = "Neplatná barva, musí být v #rrggbb hexadecimálním formátu: " `mappend` t
Yesod/Form/I18n/Dutch.hs view
@@ -24,3 +24,4 @@ dutchFormMessage MsgBoolYes = "Ja" dutchFormMessage MsgBoolNo = "Nee" dutchFormMessage MsgDelete = "Verwijderen?"+dutchFormMessage (MsgInvalidHexColorFormat t) = "Ongeldige kleur, moet de hexadecimale indeling #rrggbb hebben: " `mappend` t
Yesod/Form/I18n/English.hs view
@@ -24,3 +24,4 @@ englishFormMessage MsgBoolYes = "Yes" englishFormMessage MsgBoolNo = "No" englishFormMessage MsgDelete = "Delete?"+englishFormMessage (MsgInvalidHexColorFormat t) = "Invalid color, must be in #rrggbb hexadecimal format: " `mappend` t
Yesod/Form/I18n/French.hs view
@@ -24,3 +24,4 @@ frenchFormMessage MsgBoolYes = "Oui" frenchFormMessage MsgBoolNo = "Non" frenchFormMessage MsgDelete = "Détruire ?"+frenchFormMessage (MsgInvalidHexColorFormat t) = "Couleur non valide, doit être au format hexadécimal #rrggbb: " `mappend` t
Yesod/Form/I18n/German.hs view
@@ -24,3 +24,4 @@ germanFormMessage MsgBoolYes = "Ja" germanFormMessage MsgBoolNo = "Nein" germanFormMessage MsgDelete = "Löschen?"+germanFormMessage (MsgInvalidHexColorFormat t) = "Ungültige Farbe, muss im Hexadezimalformat #rrggbb vorliegen: " `mappend` t
Yesod/Form/I18n/Japanese.hs view
@@ -24,3 +24,4 @@ japaneseFormMessage MsgBoolYes = "はい" japaneseFormMessage MsgBoolNo = "いいえ" japaneseFormMessage MsgDelete = "削除しますか?"+japaneseFormMessage (MsgInvalidHexColorFormat t) = "無効な色。#rrggbb16進形式である必要があります: " `mappend` t
Yesod/Form/I18n/Korean.hs view
@@ -24,3 +24,4 @@ koreanFormMessage MsgBoolYes = "예" koreanFormMessage MsgBoolNo = "아니오" koreanFormMessage MsgDelete = "삭제하시겠습니까?"+koreanFormMessage (MsgInvalidHexColorFormat t) = "색상이 잘못되었습니다. #rrggbb 16진수 형식이어야 합니다.: " `mappend` t
Yesod/Form/I18n/Norwegian.hs view
@@ -24,3 +24,4 @@ norwegianBokmålFormMessage MsgBoolNo = "Nei" norwegianBokmålFormMessage MsgDelete = "Slette?" norwegianBokmålFormMessage MsgCsrfWarning = "Som beskyttelse mot «cross-site request forgery»-angrep, vennligst bekreft innsendt skjema."+norwegianBokmålFormMessage (MsgInvalidHexColorFormat t) = "Ugyldig farge, må være i #rrggbb heksadesimalt format: " `mappend` t
Yesod/Form/I18n/Portuguese.hs view
@@ -24,3 +24,4 @@ portugueseFormMessage MsgBoolYes = "Sim" portugueseFormMessage MsgBoolNo = "Não" portugueseFormMessage MsgDelete = "Remover?"+portugueseFormMessage (MsgInvalidHexColorFormat t) = "Cor inválida, deve estar no formato #rrggbb hexadecimal: " `mappend` t
Yesod/Form/I18n/Russian.hs view
@@ -24,3 +24,4 @@ russianFormMessage MsgBoolYes = "Да" russianFormMessage MsgBoolNo = "Нет" russianFormMessage MsgDelete = "Удалить?"+russianFormMessage (MsgInvalidHexColorFormat t) = "Недопустимое значение цвета, должен быть в шестнадцатеричном формате #rrggbb: " `mappend` t
Yesod/Form/I18n/Spanish.hs view
@@ -25,3 +25,4 @@ spanishFormMessage MsgBoolYes = "Sí" spanishFormMessage MsgBoolNo = "No" spanishFormMessage MsgDelete = "¿Eliminar?"+spanishFormMessage (MsgInvalidHexColorFormat t) = "Color no válido, debe estar en formato hexadecimal #rrggbb: " `mappend` t
Yesod/Form/I18n/Swedish.hs view
@@ -24,3 +24,4 @@ swedishFormMessage MsgBoolNo = "Nej" swedishFormMessage MsgDelete = "Radera?" swedishFormMessage MsgCsrfWarning = "Som skydd mot \"cross-site request forgery\" attacker, vänligen bekräfta skickandet av formuläret."+swedishFormMessage (MsgInvalidHexColorFormat t) = "Ogiltig färg, måste vara i #rrggbb hexadecimalt format: " `mappend` t
Yesod/Form/Types.hs view
@@ -229,4 +229,5 @@ | MsgBoolYes | MsgBoolNo | MsgDelete+ | MsgInvalidHexColorFormat Text deriving (Show, Eq, Read)
yesod-form.cabal view
@@ -1,6 +1,6 @@ cabal-version: >= 1.10 name: yesod-form-version: 1.7.0+version: 1.7.2 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -10,7 +10,7 @@ stability: Stable build-type: Simple homepage: http://www.yesodweb.com/-description: API docs and the README are available at <http://www.stackage.org/package/yesod-form>. Third-party packages which you can find useful: <http://hackage.haskell.org/package/yesod-form-richtext yesod-form-richtext> - richtext form fields (currntly it provides only Summernote support).+description: API docs and the README are available at <http://www.stackage.org/package/yesod-form>. Third-party packages which you can find useful: <http://hackage.haskell.org/package/yesod-form-richtext yesod-form-richtext> - richtext form fields (currently it provides only Summernote support). extra-source-files: ChangeLog.md README.md