passwordField

This commit is contained in:
Michael Snoyman 2010-11-22 07:47:53 +02:00
parent 967ad7ec80
commit d15368065f
4 changed files with 30 additions and 4 deletions

View File

@ -6,6 +6,7 @@ module Yesod.Form.Fields
( -- * Fields ( -- * Fields
-- ** Required -- ** Required
stringField stringField
, passwordField
, textareaField , textareaField
, hiddenField , hiddenField
, intField , intField
@ -20,6 +21,7 @@ module Yesod.Form.Fields
, fileField , fileField
-- ** Optional -- ** Optional
, maybeStringField , maybeStringField
, maybePasswordField
, maybeTextareaField , maybeTextareaField
, maybeHiddenField , maybeHiddenField
, maybeIntField , maybeIntField
@ -65,6 +67,14 @@ maybeStringField :: (IsForm f, FormType f ~ Maybe String)
=> FormFieldSettings -> Maybe (Maybe String) -> f => FormFieldSettings -> Maybe (Maybe String) -> f
maybeStringField = optionalFieldHelper stringFieldProfile maybeStringField = optionalFieldHelper stringFieldProfile
passwordField :: (IsForm f, FormType f ~ String)
=> FormFieldSettings -> Maybe String -> f
passwordField = requiredFieldHelper passwordFieldProfile
maybePasswordField :: (IsForm f, FormType f ~ Maybe String)
=> FormFieldSettings -> Maybe (Maybe String) -> f
maybePasswordField = optionalFieldHelper passwordFieldProfile
intInput :: Integral i => String -> FormInput sub master i intInput :: Integral i => String -> FormInput sub master i
intInput n = intInput n =
mapFormXml fieldsToInput $ mapFormXml fieldsToInput $

View File

@ -4,6 +4,7 @@
{-# LANGUAGE CPP #-} {-# LANGUAGE CPP #-}
module Yesod.Form.Profiles module Yesod.Form.Profiles
( stringFieldProfile ( stringFieldProfile
, passwordFieldProfile
, textareaFieldProfile , textareaFieldProfile
, hiddenFieldProfile , hiddenFieldProfile
, intFieldProfile , intFieldProfile
@ -166,6 +167,20 @@ stringFieldProfile = FieldProfile
|] |]
} }
passwordFieldProfile :: FieldProfile s m String
passwordFieldProfile = FieldProfile
{ fpParse = Right
, fpRender = id
, fpWidget = \theId name val isReq -> addHamlet
#if GHC7
[hamlet|
#else
[$hamlet|
#endif
%input#$theId$!name=$name$!type=password!:isReq:required!value=$val$
|]
}
readMay :: Read a => String -> Maybe a readMay :: Read a => String -> Maybe a
readMay s = case reads s of readMay s = case reads s of
(x, _):_ -> Just x (x, _):_ -> Just x

View File

@ -61,7 +61,7 @@ getRootR = defaultLayout $ wrapper $ do
addHtmlHead [$hamlet|%meta!keywords=haskell|] addHtmlHead [$hamlet|%meta!keywords=haskell|]
handleFormR = do handleFormR = do
(res, form, enctype, hidden) <- runFormPost $ fieldsToTable $ (,,,,,,,,,,) (res, form, enctype, hidden) <- runFormPost $ fieldsToTable $ (,,,,,,,,,,,)
<$> stringField (FormFieldSettings "My Field" "Some tooltip info" Nothing Nothing) Nothing <$> stringField (FormFieldSettings "My Field" "Some tooltip info" Nothing Nothing) Nothing
<*> stringField ("Another field") (Just "some default text") <*> stringField ("Another field") (Just "some default text")
<*> intField (FormFieldSettings "A number field" "some nums" Nothing Nothing) (Just 5) <*> intField (FormFieldSettings "A number field" "some nums" Nothing Nothing) (Just 5)
@ -85,11 +85,12 @@ handleFormR = do
<*> maybeEmailField ("An e-mail addres") Nothing <*> maybeEmailField ("An e-mail addres") Nothing
<*> maybeTextareaField "A text area" Nothing <*> maybeTextareaField "A text area" Nothing
<*> maybeFileField "Any file" <*> maybeFileField "Any file"
<*> maybePasswordField "Enter a password" Nothing
let (mhtml, mfile) = case res of let (mhtml, mfile) = case res of
FormSuccess (_, _, _, _, _, _, _, x, _, _, y) -> (Just x, y) FormSuccess (_, _, _, _, _, _, _, x, _, _, y, _) -> (Just x, y)
_ -> (Nothing, Nothing) _ -> (Nothing, Nothing)
let txt = case res of let txt = case res of
FormSuccess (_, _, _, _, _, _, _, _, _, Just x, _) -> Just x FormSuccess (_, _, _, _, _, _, _, _, _, Just x, _, _) -> Just x
_ -> Nothing _ -> Nothing
defaultLayout $ do defaultLayout $ do
addCassius [$cassius| addCassius [$cassius|

View File

@ -1,5 +1,5 @@
name: yesod name: yesod
version: 0.6.3.1 version: 0.6.4
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>