daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // String -> Formlet a xml -> Formlet a xml
  2. function label(label,formlet) {
  3.         return transformXml(function(xml){
  4.                           return "<p>"+label+":"+xml+"</p>";}
  5.                            ,formlet);
  6. }
  7.  
  8.  
  9. var name = label("Name",textInput);
  10.  
  11. var age = label("Age",textInput);
  12.  
  13. var formlet = appendFormlets(tuple,name,age);
  14.  
  15. var res = runS(  formlet
  16.               ,  {id:0,env:[[0,"Craig"]
  17.                            ,[1,"62"]]}
  18.               );
  19. showPrint(res);
  20.  
  21. var res = runS(  formlet
  22.               ,  {id:0,env:[[1,"62"]]}
  23.               );
  24. showPrint(res);
  25.  
  26. var adultAge = ensure(function(x){return x>18;}
  27.                      ,"Must be 18 or over."
  28.                      ,age);
  29.  
  30. var res = runS(  appendFormlets(tuple,name,adultAge)
  31.               ,  {id:0,env:[[0,"Dave"]
  32.                            ,[1,"62"]]}
  33.               );
  34. showPrint(res);
  35.  
  36. var res = runS(  appendFormlets(tuple,name,adultAge)
  37.               ,  {id:0,env:[[0,"Dave"]
  38.                            ,[1,"12"]]}
  39.               );
  40. showPrint(res);
  41.  
  42. /* Output */
  43.  
  44.     (Formlet (Success ((Craig,62)) "<p>Name:<input type='text' name='0' id='0' value='Craig'></p><p>Age:<input type='text' name='1' id='1' value='62'></p>"),FormState (2 [0 => (0,Craig),1 => (1,62)]))
  45.  
  46.     (Formlet (Failure ([0 => "0 is not in the data."]) "<p>Name:<input type='text' name='0' id='0' value=''></p><p>Age:<input type='text' name='1' id='1' value='62'></p>"),FormState (2 [0 => (1,62)]))
  47.  
  48.     (Formlet (Success ((Dave,62)) "<p>Name:<input type='text' name='0' id='0' value='Dave'></p><p>Age:<input type='text' name='1' id='1' value='62'></p>"),FormState (2 [0 => (0,Dave),1 => (1,62)]))
  49.  
  50.     (Formlet (Failure ([0 => "Must be 18 or over."]) "<p>Name:<input type='text' name='0' id='0' value='Dave'></p><p>Age:<input type='text' name='1' id='1' value='12'></p>"),FormState (2 [0 => (0,Dave),1 => (1,12)]))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top