Merge branch 'master' into dedicated-radio
This commit is contained in:
commit
c6824d7543
@ -481,6 +481,30 @@ secretJsonField = Field{..}
|
|||||||
|]
|
|]
|
||||||
fieldEnctype = UrlEncoded
|
fieldEnctype = UrlEncoded
|
||||||
|
|
||||||
|
boolField :: ( MonadHandler m
|
||||||
|
, HandlerSite m ~ UniWorX
|
||||||
|
)
|
||||||
|
=> Field m Bool
|
||||||
|
boolField = Field
|
||||||
|
{ fieldParse = \e _ -> return $ boolParser e
|
||||||
|
, fieldView = \theId name attrs val isReq -> $(widgetFile "widgets/fields/bool")
|
||||||
|
, fieldEnctype = UrlEncoded
|
||||||
|
}
|
||||||
|
where
|
||||||
|
boolParser [] = Right Nothing
|
||||||
|
boolParser (x:_) = case x of
|
||||||
|
"" -> Right Nothing
|
||||||
|
"none" -> Right Nothing
|
||||||
|
"yes" -> Right $ Just True
|
||||||
|
"on" -> Right $ Just True
|
||||||
|
"no" -> Right $ Just False
|
||||||
|
"true" -> Right $ Just True
|
||||||
|
"false" -> Right $ Just False
|
||||||
|
t -> Left $ SomeMessage $ MsgInvalidBool t
|
||||||
|
showVal = either (\_ -> False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
funcForm :: forall k v m.
|
funcForm :: forall k v m.
|
||||||
( Finite k, Ord k
|
( Finite k, Ord k
|
||||||
|
|||||||
@ -3,7 +3,7 @@ module Import.NoFoundation
|
|||||||
, MForm
|
, MForm
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import ClassyPrelude.Yesod as Import hiding (formatTime, derivePersistFieldJSON, addMessage, addMessageI, (.=), MForm, Proxy, foldlM, static)
|
import ClassyPrelude.Yesod as Import hiding (formatTime, derivePersistFieldJSON, addMessage, addMessageI, (.=), MForm, Proxy, foldlM, static, boolField)
|
||||||
import Model as Import
|
import Model as Import
|
||||||
import Model.Types.JSON as Import
|
import Model.Types.JSON as Import
|
||||||
import Model.Migration as Import
|
import Model.Migration as Import
|
||||||
|
|||||||
14
templates/widgets/fields/bool.hamlet
Normal file
14
templates/widgets/fields/bool.hamlet
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
$newline never
|
||||||
|
<div .radio-group>
|
||||||
|
$if not isReq
|
||||||
|
<div .radio>
|
||||||
|
<input id=#{theId}-none *{attrs} type=radio name=#{name} value=none checked>
|
||||||
|
<label for=#{theId}-none>_{MsgSelectNone}
|
||||||
|
|
||||||
|
<div .radio>
|
||||||
|
<input id=#{theId}-yes *{attrs} type=radio name=#{name} value=yes :showVal id val:checked>
|
||||||
|
<label for=#{theId}-yes>_{MsgBoolYes}
|
||||||
|
|
||||||
|
<div .radio>
|
||||||
|
<input id=#{theId}-no *{attrs} type=radio name=#{name} value=no :showVal not val:checked>
|
||||||
|
<label for=#{theId}-no>_{MsgBoolNo}
|
||||||
Loading…
Reference in New Issue
Block a user