Color field (#1748)
This PR adds a new colorField function to create an html color field (<input type="color">) as described at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input/color
This commit is contained in:
parent
5bd872be02
commit
48d05fd6ab
@ -1,5 +1,9 @@
|
||||
# ChangeLog for yesod-form
|
||||
|
||||
## 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)
|
||||
|
||||
@ -62,6 +62,7 @@ module Yesod.Form.Fields
|
||||
, optionsPairs
|
||||
, optionsPairsGrouped
|
||||
, optionsEnum
|
||||
, colorField
|
||||
) where
|
||||
|
||||
import Yesod.Form.Types
|
||||
@ -117,6 +118,8 @@ import Data.String (IsString)
|
||||
import Data.Monoid
|
||||
#endif
|
||||
|
||||
import Data.Char (isHexDigit)
|
||||
|
||||
defaultFormMessage :: FormMessage -> Text
|
||||
defaultFormMessage = englishFormMessage
|
||||
|
||||
@ -948,3 +951,23 @@ prependZero t0 = if T.null t1
|
||||
-- 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
|
||||
|
||||
@ -24,3 +24,4 @@ chineseFormMessage (MsgInvalidBool t) = "无效的逻辑值: " `mappend` t
|
||||
chineseFormMessage MsgBoolYes = "是"
|
||||
chineseFormMessage MsgBoolNo = "否"
|
||||
chineseFormMessage MsgDelete = "删除?"
|
||||
chineseFormMessage (MsgInvalidHexColorFormat t) = "颜色无效,必须为 #rrggbb 十六进制格式: " `mappend` t
|
||||
|
||||
@ -24,3 +24,4 @@ croatianFormMessage (MsgInvalidBool t) = "Logička vrijednost nije valjana: "
|
||||
croatianFormMessage MsgBoolYes = "Da"
|
||||
croatianFormMessage MsgBoolNo = "Ne"
|
||||
croatianFormMessage MsgDelete = "Izbrisati?"
|
||||
croatianFormMessage (MsgInvalidHexColorFormat t) = "Nevažeća boja, mora biti u #rrggbb heksadecimalnom formatu: " `mappend` t
|
||||
|
||||
@ -24,3 +24,4 @@ czechFormMessage (MsgInvalidBool t) = "Neplatná pravdivostní hodnota: " `mappe
|
||||
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
|
||||
|
||||
@ -24,3 +24,4 @@ dutchFormMessage (MsgInvalidBool t) = "Ongeldige waarheidswaarde: " `mappend`
|
||||
dutchFormMessage MsgBoolYes = "Ja"
|
||||
dutchFormMessage MsgBoolNo = "Nee"
|
||||
dutchFormMessage MsgDelete = "Verwijderen?"
|
||||
dutchFormMessage (MsgInvalidHexColorFormat t) = "Ongeldige kleur, moet de hexadecimale indeling #rrggbb hebben: " `mappend` t
|
||||
|
||||
@ -24,3 +24,4 @@ englishFormMessage (MsgInvalidBool t) = "Invalid boolean: " `mappend` t
|
||||
englishFormMessage MsgBoolYes = "Yes"
|
||||
englishFormMessage MsgBoolNo = "No"
|
||||
englishFormMessage MsgDelete = "Delete?"
|
||||
englishFormMessage (MsgInvalidHexColorFormat t) = "Invalid color, must be in #rrggbb hexadecimal format: " `mappend` t
|
||||
|
||||
@ -24,3 +24,4 @@ frenchFormMessage (MsgInvalidBool t) = "Booléen invalide : " `mappend` t
|
||||
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
|
||||
|
||||
@ -24,3 +24,4 @@ germanFormMessage (MsgInvalidBool t) = "Ungültiger Wahrheitswert: " `mappend` t
|
||||
germanFormMessage MsgBoolYes = "Ja"
|
||||
germanFormMessage MsgBoolNo = "Nein"
|
||||
germanFormMessage MsgDelete = "Löschen?"
|
||||
germanFormMessage (MsgInvalidHexColorFormat t) = "Ungültige Farbe, muss im Hexadezimalformat #rrggbb vorliegen: " `mappend` t
|
||||
|
||||
@ -24,3 +24,4 @@ japaneseFormMessage (MsgInvalidBool t) = "無効なbool値です: " `mappend` t
|
||||
japaneseFormMessage MsgBoolYes = "はい"
|
||||
japaneseFormMessage MsgBoolNo = "いいえ"
|
||||
japaneseFormMessage MsgDelete = "削除しますか?"
|
||||
japaneseFormMessage (MsgInvalidHexColorFormat t) = "無効な色。#rrggbb16進形式である必要があります: " `mappend` t
|
||||
|
||||
@ -24,3 +24,4 @@ koreanFormMessage (MsgInvalidBool t) = "잘못된 불(boolean)입니다: " `mapp
|
||||
koreanFormMessage MsgBoolYes = "예"
|
||||
koreanFormMessage MsgBoolNo = "아니오"
|
||||
koreanFormMessage MsgDelete = "삭제하시겠습니까?"
|
||||
koreanFormMessage (MsgInvalidHexColorFormat t) = "색상이 잘못되었습니다. #rrggbb 16진수 형식이어야 합니다.: " `mappend` t
|
||||
|
||||
@ -24,3 +24,4 @@ norwegianBokmålFormMessage MsgBoolYes = "Ja"
|
||||
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
|
||||
|
||||
@ -24,3 +24,4 @@ portugueseFormMessage (MsgInvalidBool t) = "Booleano inválido: " `mappend` t
|
||||
portugueseFormMessage MsgBoolYes = "Sim"
|
||||
portugueseFormMessage MsgBoolNo = "Não"
|
||||
portugueseFormMessage MsgDelete = "Remover?"
|
||||
portugueseFormMessage (MsgInvalidHexColorFormat t) = "Cor inválida, deve estar no formato #rrggbb hexadecimal: " `mappend` t
|
||||
|
||||
@ -24,3 +24,4 @@ russianFormMessage (MsgInvalidBool t) = "Неверное логическое
|
||||
russianFormMessage MsgBoolYes = "Да"
|
||||
russianFormMessage MsgBoolNo = "Нет"
|
||||
russianFormMessage MsgDelete = "Удалить?"
|
||||
russianFormMessage (MsgInvalidHexColorFormat t) = "Недопустимое значение цвета, должен быть в шестнадцатеричном формате #rrggbb: " `mappend` t
|
||||
|
||||
@ -25,3 +25,4 @@ spanishFormMessage (MsgInvalidBool t) = "Booleano inválido: " `mappend` t
|
||||
spanishFormMessage MsgBoolYes = "Sí"
|
||||
spanishFormMessage MsgBoolNo = "No"
|
||||
spanishFormMessage MsgDelete = "¿Eliminar?"
|
||||
spanishFormMessage (MsgInvalidHexColorFormat t) = "Color no válido, debe estar en formato hexadecimal #rrggbb: " `mappend` t
|
||||
|
||||
@ -24,3 +24,4 @@ swedishFormMessage MsgBoolYes = "Ja"
|
||||
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
|
||||
|
||||
@ -229,4 +229,5 @@ data FormMessage = MsgInvalidInteger Text
|
||||
| MsgBoolYes
|
||||
| MsgBoolNo
|
||||
| MsgDelete
|
||||
| MsgInvalidHexColorFormat Text
|
||||
deriving (Show, Eq, Read)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
cabal-version: >= 1.10
|
||||
name: yesod-form
|
||||
version: 1.7.0
|
||||
version: 1.7.1
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
author: Michael Snoyman <michael@snoyman.com>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user