hunk ./debian/patches/30_checkbox.diff 3 -@@ -1,4 +1,4 @@ --module Text.Formlets ( input', inputFile, fmapFst, nothingIfNull -+module Text.Formlets ( input', input'', inputFile, fmapFst, nothingIfNull - , check, ensure, ensures - , ensureM, checkM, pureM - , runFormState -@@ -73,6 +73,20 @@ +@@ -62,14 +62,14 @@ + where errors = [ err | (p, err) <- ps, not $ p x ] + + -- | Helper function for genereting input components based forms. +-input' :: Monad m => (String -> String -> xml) -> Maybe String -> Form xml m String +-input' i defaultValue = Form $ \env -> mkInput env <$> freshName ++input' :: Monad m => (String -> String -> xml) -> Maybe String -> Maybe String -> Form xml m String ++input' i defaultResult defaultValue = Form $ \env -> mkInput env <$> freshName + where mkInput env name = (return . fromLeft name . (lookup name), + return (i name (value name env)), UrlEncoded) + value name env = maybe (maybe "" id defaultValue) fromLeft' (lookup name env) + fromLeft' (Left x) = x + fromLeft' _ = "" +- fromLeft n Nothing = Failure [n ++ " is not in the data"] ++ fromLeft n Nothing = maybe (Failure [n ++ " is not in the data"]) Success defaultResult hunk ./debian/patches/30_checkbox.diff 21 -+-- | Modified version of input' for checkboxes. Unlike other inputs, -+-- when they are unchecked nothing appears in the response, so the "is -+-- not in the data" error is not an error here. -+input'' :: Monad m => (String -> String -> xml) -> Maybe String -> Form xml m String -+input'' i defaultValue = Form $ \env -> mkInput env <$> freshName -+ where mkInput env name = (return . fromLeft name . (lookup name), -+ i name (value name env), UrlEncoded) -+ value name env = maybe (maybe "" id defaultValue) fromLeft' (lookup name env) -+ fromLeft' (Left x) = x -+ fromLeft' _ = "" -+ fromLeft n Nothing = Success "" -+ fromLeft n (Just (Left x)) = Success x -+ fromLeft n _ = Failure [n ++ " is a file."] -+ - -- | A File input widget. - inputFile :: Monad m - => (String -> xml) -- ^ Generates the xml for the file-upload widget based on the name hunk ./debian/patches/30_checkbox.diff 12 - return (i name (value name env)), UrlEncoded) + i name (value name env), UrlEncoded) hunk ./debian/changelog 1 +haskell-formlets (0.4.7-3) unstable; urgency=low + + * Remove input'', instead add a Maybe String argument to input' + providing the defaultResult of the form, the result used when + no data from form appears in the result. This is necessary + for certain inputs such as checkboxes that don't always appear + in the form result, or for inputs that might be disabled. + + -- David Fox Sat, 03 Jan 2009 07:01:19 -0800 + hunk ./debian/patches/30_checkbox.diff 21 +--- x/Text/XHtml/Strict/Formlets.hs~ 2008-08-29 07:13:42.000000000 -0700 ++++ x/Text/XHtml/Strict/Formlets.hs 2009-01-03 05:53:30.000000000 -0800 +@@ -20,18 +20,18 @@ + + -- | An input field with an optional value + input :: Monad m => Maybe String -> XHtmlForm m String +-input = input' (\n v -> X.textfield n ! [X.value v]) ++input = input' (\n v -> X.textfield n ! [X.value v]) Nothing + + textarea :: Monad m => Maybe String -> XHtmlForm m String +-textarea = input' (\n v -> X.textarea (X.toHtml v) ! [X.name n]) ++textarea = input' (\n v -> X.textarea (X.toHtml v) ! [X.name n]) Nothing + + -- | A password field with an optional value + password :: Monad m => Maybe String -> XHtmlForm m String +-password = input' (\n v -> X.password n ! [X.value v]) ++password = input' (\n v -> X.password n ! [X.value v]) Nothing + + -- | A hidden input field + hidden :: Monad m => Maybe String -> XHtmlForm m String +-hidden = input' X.hidden ++hidden = input' X.hidden Nothing + + -- | A validated integer component + inputInteger :: Monad m => Maybe Integer -> XHtmlForm m Integer +@@ -42,7 +42,7 @@ + + -- | A radio choice + radio :: Monad m => [(String, String)] -> Maybe String -> XHtmlForm m String +-radio choices = input' mkRadios -- todo: validate that the result was in the choices ++radio choices = input' mkRadios Nothing -- todo: validate that the result was in the choices + where radio n v i = X.input ! [X.thetype "radio", X.name n, X.identifier i, X.theclass "radio", X.value v] + mkRadios name selected = X.concatHtml $ map (mkRadio name selected) (zip choices [1..]) + mkRadio name selected ((value, label), idx) = (radio name value ident) ! attrs +@@ -59,7 +59,7 @@ + convert v = maybeRead' v "Conversion error" + + selectRaw :: Monad m => [(String, String)] -> Maybe String -> XHtmlForm m String +-selectRaw choices = input' mkChoices -- todo: validate that the result was in the choices ++selectRaw choices = input' mkChoices Nothing -- todo: validate that the result was in the choices + where mkChoices name selected = X.select ! [X.name name] $ X.concatHtml $ map (mkChoice selected) choices + mkChoice selected (value, label) = X.option ! (attrs ++ [X.value value]) << label + where attrs | selected == value = [X.selected]