IsString instance for FormFieldSettings
This commit is contained in:
parent
1a273387d6
commit
cc102b67d9
@ -46,7 +46,6 @@ module Yesod.Form
|
||||
, emailFieldProfile
|
||||
, urlFieldProfile
|
||||
, FormFieldSettings (..)
|
||||
, labelSettings
|
||||
-- * Pre-built fields
|
||||
, stringField
|
||||
, maybeStringField
|
||||
@ -107,6 +106,7 @@ import Control.Arrow ((&&&))
|
||||
import qualified Text.Email.Validate as Email
|
||||
import Data.List (group, sort)
|
||||
import Network.URI (parseURI)
|
||||
import Data.String (IsString (..))
|
||||
|
||||
-- | A form can produce three different results: there was no data available,
|
||||
-- the data was invalid, or there was a successful parse.
|
||||
@ -220,6 +220,8 @@ data FormFieldSettings = FormFieldSettings
|
||||
, ffsId :: Maybe String
|
||||
, ffsName :: Maybe String
|
||||
}
|
||||
instance IsString FormFieldSettings where
|
||||
fromString s = FormFieldSettings (string s) mempty Nothing Nothing
|
||||
|
||||
-- | Create a required field (ie, one that cannot be blank) from a
|
||||
-- 'FieldProfile'.ngs
|
||||
@ -793,9 +795,6 @@ emailInput n =
|
||||
nameSettings :: String -> FormFieldSettings
|
||||
nameSettings n = FormFieldSettings mempty mempty (Just n) (Just n)
|
||||
|
||||
labelSettings :: String -> FormFieldSettings
|
||||
labelSettings l = FormFieldSettings (string l) mempty Nothing Nothing
|
||||
|
||||
textareaFieldProfile :: FieldProfile sub y String
|
||||
textareaFieldProfile = FieldProfile
|
||||
{ fpParse = Right
|
||||
|
||||
@ -54,11 +54,11 @@ getRootR = applyLayoutW $ flip wrapWidget wrapper $ do
|
||||
handleFormR = do
|
||||
(res, form, enctype) <- runFormPost $ (,,,,,,,,,)
|
||||
<$> stringField (FormFieldSettings "My Field" "Some tooltip info" Nothing Nothing) Nothing
|
||||
<*> stringField (labelSettings "Another field") (Just "some default text")
|
||||
<*> stringField ("Another field") (Just "some default text")
|
||||
<*> intField (FormFieldSettings "A number field" "some nums" Nothing Nothing) (Just 5)
|
||||
<*> jqueryDayField (labelSettings "A day field") Nothing
|
||||
<*> timeField (labelSettings "A time field") Nothing
|
||||
<*> jqueryDayTimeField (labelSettings "A day/time field") Nothing
|
||||
<*> jqueryDayField ("A day field") Nothing
|
||||
<*> timeField ("A time field") Nothing
|
||||
<*> jqueryDayTimeField ("A day/time field") Nothing
|
||||
<*> boolField FormFieldSettings
|
||||
{ ffsLabel = "A checkbox"
|
||||
, ffsTooltip = ""
|
||||
@ -67,9 +67,9 @@ handleFormR = do
|
||||
} (Just False)
|
||||
<*> jqueryAutocompleteField AutoCompleteR
|
||||
(FormFieldSettings "Autocomplete" "Try it!" Nothing Nothing) Nothing
|
||||
<*> nicHtmlField (labelSettings "HTML")
|
||||
<*> nicHtmlField ("HTML")
|
||||
(Just $ string "You can put rich text here")
|
||||
<*> maybeEmailField (labelSettings "An e-mail addres") Nothing
|
||||
<*> maybeEmailField ("An e-mail addres") Nothing
|
||||
let mhtml = case res of
|
||||
FormSuccess (_, _, _, _, _, _, _, _, x, _) -> Just x
|
||||
_ -> Nothing
|
||||
|
||||
Loading…
Reference in New Issue
Block a user