From 1944f02c8414c8eb6d6c17339ae3258b58bb1746 Mon Sep 17 00:00:00 2001 From: Maximilian Tagher Date: Mon, 24 Nov 2014 14:40:11 -0500 Subject: [PATCH 1/3] Add type="time" to timeField --- yesod-form/Yesod/Form/Fields.hs | 2 +- yesod-form/hello-forms.hs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/yesod-form/Yesod/Form/Fields.hs b/yesod-form/Yesod/Form/Fields.hs index da9a02ec..81ff6bbc 100644 --- a/yesod-form/Yesod/Form/Fields.hs +++ b/yesod-form/Yesod/Form/Fields.hs @@ -160,7 +160,7 @@ timeField = Field { fieldParse = parseHelper parseTime , fieldView = \theId name attrs val isReq -> toWidget [hamlet| $newline never - + |] , fieldEnctype = UrlEncoded } diff --git a/yesod-form/hello-forms.hs b/yesod-form/hello-forms.hs index f8a1259e..8190533b 100644 --- a/yesod-form/hello-forms.hs +++ b/yesod-form/hello-forms.hs @@ -26,7 +26,7 @@ mkYesod "HelloForms" [parseRoutes| /file FileR GET POST |] -myForm = fixType $ runFormGet $ renderDivs $ pure (,,,,,,,,,,,) +myForm = fixType $ runFormGet $ renderDivs $ pure (,,,,,,,,,,,,) <*> pure "pure works!" <*> areq boolField "Bool field" Nothing <*> aopt boolField "Opt bool field" Nothing @@ -39,6 +39,7 @@ myForm = fixType $ runFormGet $ renderDivs $ pure (,,,,,,,,,,,) <*> aopt (radioFieldList fruits) "Opt radio" Nothing <*> aopt multiEmailField "Opt multi email" Nothing <*> areq nicHtmlField "NIC HTML" Nothing + <*> aopt timeField "Opt Time" Nothing instance Show Html where show = renderHtml From 33d9f5e18cb4baf967cc92cf511bce09a216b38b Mon Sep 17 00:00:00 2001 From: Maximilian Tagher Date: Tue, 25 Nov 2014 10:33:59 -0500 Subject: [PATCH 2/3] Support different types for timeField --- yesod-form/Yesod/Form/Fields.hs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/yesod-form/Yesod/Form/Fields.hs b/yesod-form/Yesod/Form/Fields.hs index 81ff6bbc..0cc4b0b3 100644 --- a/yesod-form/Yesod/Form/Fields.hs +++ b/yesod-form/Yesod/Form/Fields.hs @@ -156,11 +156,27 @@ $newline never -- -- Add the @time@ package and import the "Data.Time.LocalTime" module to use this function. timeField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay -timeField = Field +timeField = timeFieldTypeText +{-# DEPRECATED timeField "timeField currently defaults to an input of type=\"text\". In the next major release, it will default to type=\"time\". To opt in to the new functionality, use 'timeFieldTypeTime'. To keep the existing behavior, use 'timeFieldTypeText'. See https://github.com/yesodweb/yesod/pull/874 for details." #-} + +-- | Creates an input with @type="time"@. Parses time from a [H]H:MM[:SS] format, with an optional AM or PM (if not given, AM is assumed for compatibility with a 24 hour clock system). +-- +-- Add the @time@ package and import the "Data.Time.LocalTime" module to use this function. +timeFieldTypeTime :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay +timeFieldTypeTime = timeFieldOfType "time" + +-- | Creates an input with @type="text"@. Parses time from a [H]H:MM[:SS] format, with an optional AM or PM (if not given, AM is assumed for compatibility with a 24 hour clock system). +-- +-- Add the @time@ package and import the "Data.Time.LocalTime" module to use this function. +timeFieldTypeText :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay +timeFieldTypeText = timeFieldOfType "text" + +timeFieldOfType :: Monad m => RenderMessage (HandlerSite m) FormMessage => Text -> Field m TimeOfDay +timeFieldOfType inputType = Field { fieldParse = parseHelper parseTime , fieldView = \theId name attrs val isReq -> toWidget [hamlet| $newline never - + |] , fieldEnctype = UrlEncoded } From 222c9e3c991f12a8c60e23d1ff2c0561a0b846b7 Mon Sep 17 00:00:00 2001 From: Maximilian Tagher Date: Tue, 25 Nov 2014 10:56:30 -0500 Subject: [PATCH 3/3] Adds `timeFieldTypeText` and `timeFieldTypeTime`. Deprecates 'timeField' * Also documents all 3 functions --- yesod-form/Yesod/Form/Fields.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yesod-form/Yesod/Form/Fields.hs b/yesod-form/Yesod/Form/Fields.hs index 0cc4b0b3..f5c53386 100644 --- a/yesod-form/Yesod/Form/Fields.hs +++ b/yesod-form/Yesod/Form/Fields.hs @@ -21,6 +21,8 @@ module Yesod.Form.Fields , intField , dayField , timeField + , timeFieldTypeTime + , timeFieldTypeText , htmlField , emailField , multiEmailField @@ -152,20 +154,18 @@ $newline never } where showVal = either id (pack . show) --- | Parses time from a [H]H:MM[:SS] format, with an optional AM or PM (if not given, AM is assumed for compatibility with a 24 hour clock system). MTODO: should this use input type="time" ? --- --- Add the @time@ package and import the "Data.Time.LocalTime" module to use this function. +-- | An alias for 'timeFieldTypeText'. timeField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay timeField = timeFieldTypeText -{-# DEPRECATED timeField "timeField currently defaults to an input of type=\"text\". In the next major release, it will default to type=\"time\". To opt in to the new functionality, use 'timeFieldTypeTime'. To keep the existing behavior, use 'timeFieldTypeText'. See https://github.com/yesodweb/yesod/pull/874 for details." #-} +{-# DEPRECATED timeField "'timeField' currently defaults to an input of type=\"text\". In the next major release, it will default to type=\"time\". To opt in to the new functionality, use 'timeFieldTypeTime'. To keep the existing behavior, use 'timeFieldTypeText'. See 'https://github.com/yesodweb/yesod/pull/874' for details." #-} --- | Creates an input with @type="time"@. Parses time from a [H]H:MM[:SS] format, with an optional AM or PM (if not given, AM is assumed for compatibility with a 24 hour clock system). +-- | Creates an input with @type="time"@. will fallback to a text field, and Yesod will parse the time as described in 'timeFieldTypeText'. -- -- Add the @time@ package and import the "Data.Time.LocalTime" module to use this function. timeFieldTypeTime :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay timeFieldTypeTime = timeFieldOfType "time" --- | Creates an input with @type="text"@. Parses time from a [H]H:MM[:SS] format, with an optional AM or PM (if not given, AM is assumed for compatibility with a 24 hour clock system). +-- | Creates an input with @type="text"@, parsing the time from an [H]H:MM[:SS] format, with an optional AM or PM (if not given, AM is assumed for compatibility with the 24 hour clock system). -- -- Add the @time@ package and import the "Data.Time.LocalTime" module to use this function. timeFieldTypeText :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay