Browse files

editFormSplice defaults to "id" if "by" attribute missing

  • Loading branch information...
1 parent ef7a90e commit 3750df50d8a4b3831dc490699463b6b2412a0b64 @mightybyte mightybyte committed Jan 25, 2013
Showing with 5 additions and 3 deletions.
  1. +5 −3 src/Snap/Extras/FormUtils.hs
View
8 src/Snap/Extras/FormUtils.hs
@@ -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
@@ -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)

0 comments on commit 3750df5

Please sign in to comment.