Support different types for timeField
This commit is contained in:
parent
1944f02c84
commit
33d9f5e18c
@ -156,11 +156,27 @@ $newline never
|
|||||||
--
|
--
|
||||||
-- Add the @time@ package and import the "Data.Time.LocalTime" module to use this function.
|
-- 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 :: 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
|
{ fieldParse = parseHelper parseTime
|
||||||
, fieldView = \theId name attrs val isReq -> toWidget [hamlet|
|
, fieldView = \theId name attrs val isReq -> toWidget [hamlet|
|
||||||
$newline never
|
$newline never
|
||||||
<input id="#{theId}" name="#{name}" *{attrs} type="time" :isReq:required="" value="#{showVal val}">
|
<input id="#{theId}" name="#{name}" *{attrs} type="#{inputType}" :isReq:required="" value="#{showVal val}">
|
||||||
|]
|
|]
|
||||||
, fieldEnctype = UrlEncoded
|
, fieldEnctype = UrlEncoded
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user