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
-- ** Required
stringField
, passwordField
, textareaField
, hiddenField
, intField
@ -20,6 +21,7 @@ module Yesod.Form.Fields
, fileField
-- ** Optional
, maybeStringField
, maybePasswordField
, maybeTextareaField
, maybeHiddenField
, maybeIntField
@ -65,6 +67,14 @@ maybeStringField :: (IsForm f, FormType f ~ Maybe String)
=> FormFieldSettings -> Maybe (Maybe String) -> f
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 n =
mapFormXml fieldsToInput $

View File

@ -4,6 +4,7 @@
{-# LANGUAGE CPP #-}
module Yesod.Form.Profiles
( stringFieldProfile
, passwordFieldProfile
, textareaFieldProfile
, hiddenFieldProfile
, 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 s = case reads s of
(x, _):_ -> Just x

View File

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

View File

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