diff --git a/src/Handler/Admin.hs b/src/Handler/Admin.hs index a159489fe..77c7c42de 100644 --- a/src/Handler/Admin.hs +++ b/src/Handler/Admin.hs @@ -54,6 +54,24 @@ emailTestForm = (,) SelFormatDate -> d SelFormatTime -> t +makeDemoForm :: Int -> Form (Int,Bool,Double) +makeDemoForm n = identifyForm "adminTestForm" $ \html -> do -- Important: used identForm instead! + (result, widget) <- flip (renderAForm FormStandard) html $ (,,) + <$> areq (minIntField n "Zahl") (fromString $ "Ganzzahl > " ++ show n) Nothing + <* aformSection MsgFormBehaviour + <*> areq checkBoxField "Muss nächste Zahl größer sein?" (Just True) + <*> areq doubleField "Fliesskommazahl" Nothing + <* submitButton + return $ case result of + FormSuccess fsres + | errorMsgs <- validateResult fsres + , not $ null errorMsgs -> (FormFailure errorMsgs, widget) + _otherwise -> (result, widget) + where + validateResult :: (Int,Bool,Double) -> [Text] + validateResult (i,True,d) | (fromIntegral i) >= d = [tshow d <> " ist nicht größer als " <> tshow i, "Zweite Fehlermeldung", "Dritte Fehlermeldung"] + validateResult _other = [] + getAdminTestR, postAdminTestR :: Handler Html -- Demo Page. Referenzimplementierungen sollte hier gezeigt werden! getAdminTestR = postAdminTestR @@ -81,10 +99,43 @@ postAdminTestR = do ^{emailWidget} |] - defaultLayout $ - -- setTitle "Uni2work Admin Testpage" + + let demoFormAction (_i,_b,_d) = addMessage Info "All ok." + ((demoResult, formWidget),formEnctype) <- runFormPost $ makeDemoForm 7 + formResult demoResult demoFormAction + let actionUrl = AdminTestR + let showDemoResult = [whamlet| + $maybe (i,b,d) <- formResult' demoResult + Received values: +