Added urlField
This commit is contained in:
parent
13d3d020a7
commit
1a273387d6
@ -44,6 +44,7 @@ module Yesod.Form
|
|||||||
, timeFieldProfile
|
, timeFieldProfile
|
||||||
, htmlFieldProfile
|
, htmlFieldProfile
|
||||||
, emailFieldProfile
|
, emailFieldProfile
|
||||||
|
, urlFieldProfile
|
||||||
, FormFieldSettings (..)
|
, FormFieldSettings (..)
|
||||||
, labelSettings
|
, labelSettings
|
||||||
-- * Pre-built fields
|
-- * Pre-built fields
|
||||||
@ -68,6 +69,8 @@ module Yesod.Form
|
|||||||
, boolField
|
, boolField
|
||||||
, emailField
|
, emailField
|
||||||
, maybeEmailField
|
, maybeEmailField
|
||||||
|
, urlField
|
||||||
|
, maybeUrlField
|
||||||
-- * Pre-built inputs
|
-- * Pre-built inputs
|
||||||
, stringInput
|
, stringInput
|
||||||
, maybeStringInput
|
, maybeStringInput
|
||||||
@ -76,6 +79,7 @@ module Yesod.Form
|
|||||||
, dayInput
|
, dayInput
|
||||||
, maybeDayInput
|
, maybeDayInput
|
||||||
, emailInput
|
, emailInput
|
||||||
|
, urlInput
|
||||||
-- * Template Haskell
|
-- * Template Haskell
|
||||||
, mkToForm
|
, mkToForm
|
||||||
-- * Utilities
|
-- * Utilities
|
||||||
@ -102,6 +106,7 @@ import Yesod.Widget
|
|||||||
import Control.Arrow ((&&&))
|
import Control.Arrow ((&&&))
|
||||||
import qualified Text.Email.Validate as Email
|
import qualified Text.Email.Validate as Email
|
||||||
import Data.List (group, sort)
|
import Data.List (group, sort)
|
||||||
|
import Network.URI (parseURI)
|
||||||
|
|
||||||
-- | A form can produce three different results: there was no data available,
|
-- | A form can produce three different results: there was no data available,
|
||||||
-- the data was invalid, or there was a successful parse.
|
-- the data was invalid, or there was a successful parse.
|
||||||
@ -739,6 +744,29 @@ toLabel (x:rest) = toUpper x : go rest
|
|||||||
| isUpper c = ' ' : c : go cs
|
| isUpper c = ' ' : c : go cs
|
||||||
| otherwise = c : go cs
|
| otherwise = c : go cs
|
||||||
|
|
||||||
|
urlFieldProfile :: FieldProfile s y String
|
||||||
|
urlFieldProfile = FieldProfile
|
||||||
|
{ fpParse = \s -> case parseURI s of
|
||||||
|
Nothing -> Left "Invalid URL"
|
||||||
|
Just _ -> Right s
|
||||||
|
, fpRender = id
|
||||||
|
, fpHamlet = \theId name val isReq -> [$hamlet|
|
||||||
|
%input#$theId$!name=$name$!type=url!:isReq:required!value=$val$
|
||||||
|
|]
|
||||||
|
, fpWidget = const $ return ()
|
||||||
|
}
|
||||||
|
|
||||||
|
urlField :: FormFieldSettings -> FormletField sub y String
|
||||||
|
urlField = requiredFieldHelper urlFieldProfile
|
||||||
|
|
||||||
|
maybeUrlField :: FormFieldSettings -> FormletField sub y (Maybe String)
|
||||||
|
maybeUrlField = optionalFieldHelper urlFieldProfile
|
||||||
|
|
||||||
|
urlInput :: String -> FormInput sub master String
|
||||||
|
urlInput n =
|
||||||
|
mapFormXml fieldsToInput $
|
||||||
|
requiredFieldHelper urlFieldProfile (nameSettings n) Nothing
|
||||||
|
|
||||||
emailFieldProfile :: FieldProfile s y String
|
emailFieldProfile :: FieldProfile s y String
|
||||||
emailFieldProfile = FieldProfile
|
emailFieldProfile = FieldProfile
|
||||||
{ fpParse = \s -> if Email.isValid s
|
{ fpParse = \s -> if Email.isValid s
|
||||||
|
|||||||
@ -46,6 +46,7 @@ library
|
|||||||
neither >= 0.0.0 && < 0.1,
|
neither >= 0.0.0 && < 0.1,
|
||||||
MonadCatchIO-transformers >= 0.2.2.0 && < 0.3,
|
MonadCatchIO-transformers >= 0.2.2.0 && < 0.3,
|
||||||
data-object >= 0.3.1 && < 0.4,
|
data-object >= 0.3.1 && < 0.4,
|
||||||
|
network >= 2.2.1.5 && < 2.3,
|
||||||
email-validate >= 0.2.5 && < 0.3
|
email-validate >= 0.2.5 && < 0.3
|
||||||
exposed-modules: Yesod
|
exposed-modules: Yesod
|
||||||
Yesod.Content
|
Yesod.Content
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user