Skip to content

Commit

Permalink
editFormSplice defaults to "id" if "by" attribute missing
Browse files Browse the repository at this point in the history
  • Loading branch information
mightybyte committed Jan 25, 2013
1 parent ef7a90e commit 3750df5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Snap/Extras/FormUtils.hs
Expand Up @@ -181,9 +181,11 @@ readTrans a = maybe (Error "Unrecognized input") Success $ readMay . T.unpack $

-------------------------------------------------------------------------------
-- | Constructs a generalized edit form splice that looks up an ID param
-- specified by the "by" attribute. You might use this splice as follows:
-- specified by the @by@ attribute. You might use this splice as follows:
--
-- <editFormSplice by="id">
-- > <editFormSplice by="id">
--
-- If you don't specify the @by@ attribute, the default is @by=\"id\"@.
editFormSplice :: (Monad m, MonadSnap n)
=> (n (Maybe a) -> HeistT n m b)
-- ^ Function for generating a splice from an optional default
Expand All @@ -193,9 +195,9 @@ editFormSplice :: (Monad m, MonadSnap n)
-> HeistT n m b
editFormSplice formSplice getById = do
node <- getParamNode
let param = fromMaybe "id" $ X.getAttribute "by" node
formSplice $ do
runMaybeT $ do
param <- MaybeT $ return $ X.getAttribute "by" node
key <- MaybeT $ getParam $ encodeUtf8 param
MaybeT (getById key)

Expand Down

0 comments on commit 3750df5

Please sign in to comment.