Permalink
Browse files

Bit of documentation

  • Loading branch information...
1 parent 6019d83 commit ebc59dec1b30bd61c9cf83115038f88ba4b4783b @jaspervdj committed Jun 19, 2012
Showing with 5 additions and 2 deletions.
  1. +5 −2 digestive-functors/src/Text/Digestive/Form.hs
@@ -84,15 +84,18 @@ choice' items def = choiceWith' (zip makeRefs items) def
--------------------------------------------------------------------------------
--- | Experimental
+-- | Allows you to assign your own values: these values will be used in the
+-- resulting HTML instead of the default @[0 ..]@. This fixes some race
+-- conditions that might otherwise appear, e.g. if new choice items are added to
+-- some database while a user views and submits the form...
choiceWith :: (Eq a, Monad m) => [(Text, (a, v))] -> Formlet v m a
choiceWith items def = choiceWith' items def'
where
def' = def >>= (\d -> findIndex ((== d) . fst . snd) items)
--------------------------------------------------------------------------------
--- | Experimental
+-- | A version of 'choiceWith' for when you have no good 'Eq' instance.
choiceWith' :: Monad m => [(Text, (a, v))] -> Maybe Int -> Form v m a
choiceWith' items def = fmap fst $ Pure Nothing $ Choice items def'
where

0 comments on commit ebc59de

Please sign in to comment.