Fancy form widgets
This commit is contained in:
parent
5354c03a2c
commit
9fde607bd8
@ -50,14 +50,19 @@ module Yesod.Form
|
|||||||
, maybeDoubleField
|
, maybeDoubleField
|
||||||
, dayField
|
, dayField
|
||||||
, maybeDayField
|
, maybeDayField
|
||||||
|
, jqueryDayField
|
||||||
|
, maybeJqueryDayField
|
||||||
, timeField
|
, timeField
|
||||||
, maybeTimeField
|
, maybeTimeField
|
||||||
, htmlField
|
, htmlField
|
||||||
, maybeHtmlField
|
, maybeHtmlField
|
||||||
|
, nicHtmlField
|
||||||
|
, maybeNicHtmlField
|
||||||
, selectField
|
, selectField
|
||||||
, maybeSelectField
|
, maybeSelectField
|
||||||
, boolField
|
, boolField
|
||||||
, jqueryAutocompleteField
|
, jqueryAutocompleteField
|
||||||
|
, maybeJqueryAutocompleteField
|
||||||
-- * Pre-built inputs
|
-- * Pre-built inputs
|
||||||
, stringInput
|
, stringInput
|
||||||
, maybeStringInput
|
, maybeStringInput
|
||||||
@ -322,6 +327,9 @@ instance ToFormField Day where
|
|||||||
instance ToFormField (Maybe Day) where
|
instance ToFormField (Maybe Day) where
|
||||||
toFormField = optionalFieldHelper dayFieldProfile
|
toFormField = optionalFieldHelper dayFieldProfile
|
||||||
|
|
||||||
|
jqueryDayField = requiredFieldHelper jqueryDayFieldProfile
|
||||||
|
maybeJqueryDayField = optionalFieldHelper jqueryDayFieldProfile
|
||||||
|
|
||||||
jqueryDayFieldProfile :: FieldProfile sub y JqueryDay
|
jqueryDayFieldProfile :: FieldProfile sub y JqueryDay
|
||||||
jqueryDayFieldProfile = FieldProfile
|
jqueryDayFieldProfile = FieldProfile
|
||||||
{ fpParse = maybe
|
{ fpParse = maybe
|
||||||
@ -434,6 +442,9 @@ instance ToFormField (Maybe (Html ())) where
|
|||||||
newtype NicHtml = NicHtml { unNicHtml :: Html () }
|
newtype NicHtml = NicHtml { unNicHtml :: Html () }
|
||||||
deriving PersistField
|
deriving PersistField
|
||||||
|
|
||||||
|
nicHtmlField = requiredFieldHelper nicHtmlFieldProfile
|
||||||
|
maybeNicHtmlField = optionalFieldHelper nicHtmlFieldProfile
|
||||||
|
|
||||||
nicHtmlFieldProfile :: FieldProfile sub y NicHtml
|
nicHtmlFieldProfile :: FieldProfile sub y NicHtml
|
||||||
nicHtmlFieldProfile = FieldProfile
|
nicHtmlFieldProfile = FieldProfile
|
||||||
{ fpParse = Right . NicHtml . preEscapedString
|
{ fpParse = Right . NicHtml . preEscapedString
|
||||||
@ -680,6 +691,8 @@ toLabel (x:rest) = toUpper x : go rest
|
|||||||
|
|
||||||
jqueryAutocompleteField src = requiredFieldHelper
|
jqueryAutocompleteField src = requiredFieldHelper
|
||||||
$ jqueryAutocompleteFieldProfile src
|
$ jqueryAutocompleteFieldProfile src
|
||||||
|
maybeJqueryAutocompleteField src = optionalFieldHelper
|
||||||
|
$ jqueryAutocompleteFieldProfile src
|
||||||
|
|
||||||
jqueryAutocompleteFieldProfile :: Route y -> FieldProfile sub y String
|
jqueryAutocompleteFieldProfile :: Route y -> FieldProfile sub y String
|
||||||
jqueryAutocompleteFieldProfile src = FieldProfile
|
jqueryAutocompleteFieldProfile src = FieldProfile
|
||||||
|
|||||||
@ -40,15 +40,15 @@ handleFormR = do
|
|||||||
<$> stringField (string "My Field") (string "Some tooltip info") Nothing
|
<$> stringField (string "My Field") (string "Some tooltip info") Nothing
|
||||||
<*> stringField (string "Another field") (string "") (Just "some default text")
|
<*> stringField (string "Another field") (string "") (Just "some default text")
|
||||||
<*> intField (string "A number field") (string "some nums") (Just 5)
|
<*> intField (string "A number field") (string "some nums") (Just 5)
|
||||||
<*> dayField (string "A day field") (string "") Nothing
|
<*> jqueryDayField (string "A day field") (string "") Nothing
|
||||||
<*> timeField (string "A time field") (string "") Nothing
|
<*> timeField (string "A time field") (string "") Nothing
|
||||||
<*> boolField (string "A checkbox") (string "") (Just False)
|
<*> boolField (string "A checkbox") (string "") (Just False)
|
||||||
<*> jqueryAutocompleteField AutoCompleteR
|
<*> jqueryAutocompleteField AutoCompleteR
|
||||||
(string "Autocomplete") (string "Try it!") Nothing
|
(string "Autocomplete") (string "Try it!") Nothing
|
||||||
<*> htmlField (string "HTML") (string "")
|
<*> nicHtmlField (string "HTML") (string "")
|
||||||
(Just $ string "You can put rich text here")
|
(Just $ NicHtml $ string "You can put rich text here")
|
||||||
let mhtml = case res of
|
let mhtml = case res of
|
||||||
FormSuccess (_, _, _, _, _, _, _, x) -> Just x
|
FormSuccess (_, _, _, _, _, _, _, NicHtml x) -> Just x
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
applyLayoutW $ do
|
applyLayoutW $ do
|
||||||
addStyle [$hamlet|\.tooltip{color:#666;font-style:italic}|]
|
addStyle [$hamlet|\.tooltip{color:#666;font-style:italic}|]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user