MFlow  Create and maintain dynamic Web applications as easy and fast as console applications
Thou shall not write request handlers
 This release: 11/06/2014. (@agocorona) <>< . issues & bugs .  Mflow Source code,     source code of this site

An Integer in a text box is incremented in a loop

A text input box in a page in a loop that increase the value of the box. you can enter new values, go back and enter invalid inputs (non numbers) to see what happens.

Running example

(in the light red box):

increase an Int


increase an Int


Source code:

module IncreaseInt ( clickn) where

-- #define ALONE
#ifdef ALONE
import MFlow.Wai.Blaze.Html.All 
main= runNavigation "" . transientNav $ clickn 0
import MFlow.Wai.Blaze.Html.All hiding(page)
import Menu

-- |+| add a widget before and after another and return both results.
-- in this case, a link wraps a form field

clickn :: Int -> FlowM Html IO ()
clickn n= do
   r <- page  $ p << b <<  "increase an Int"
            ++> wlink "menu"  << p <<  "menu"      
            |+| getInt (Just n)  <* submitButton "submit"

   case r of
    (Just _,_) -> return ()  --  page  $ wlink () << p << "thanks"
    (_, Just n') -> clickn $ n'+1

comments powered by Disqus