changeset 780:0084af7af35a

subforms demo
author Adam Chlipala <adamc@hcoop.net>
date Sun, 03 May 2009 15:53:29 -0400
parents 7394368a5cad
children c884a42599f3
files demo/prose demo/subforms.ur demo/subforms.urp demo/subforms.urs
diffstat 4 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/demo/prose	Sun May 03 15:38:49 2009 -0400
+++ b/demo/prose	Sun May 03 15:53:29 2009 -0400
@@ -80,6 +80,10 @@
 
 <p>In the <tt>.urp</tt> file for this example, we give a whitelist of MIME types to be accepted.  The application will echo back to the user any file he uploads as one of those types.  You can try submitting other kinds of files to verify that they are rejected.</p>
 
+subforms.urp
+
+<p>In the examples so far, the number of inputs per form has been constant.  Often it is useful to have a varying set of form inputs.  Ur/Web provides the <tt>&lt;subforms&gt;</tt> and <tt>&lt;entry&gt;</tt> tags for grouping a list of forms with the same field names and types into a single, list-valued composite form.  This demo shows those tags in action, in a simple form echoing application that lets the user add and remove inputs.</p>
+
 listShop.urp
 
 <p>This example shows off algebraic datatypes, parametric polymorphism, and functors.</p>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/subforms.ur	Sun May 03 15:53:29 2009 -0400
@@ -0,0 +1,43 @@
+fun sub r =
+    let
+        fun sub' ls =
+            case ls of
+                [] => <xml/>
+              | r :: ls => <xml>
+                <li>{[r.Num]} = {[r.Text]}</li>
+                {sub' ls}
+              </xml>
+    in
+        return <xml><body>
+          {sub' r.Lines}
+        </body></xml>
+    end
+
+fun subforms n =
+    if n <= 0 then
+        <xml/>
+    else
+        <xml>
+          <entry>
+            <hidden{#Num} value={show n}/>
+            <li>{[n]}: <textbox{#Text}/></li>
+          </entry>
+          {subforms (n - 1)}
+        </xml>
+
+fun form n = return <xml><body>
+  <form>
+    <subforms{#Lines}>
+      {subforms n}
+    </subforms>
+    <submit action={sub}/>
+  </form>
+
+  <a link={form (n + 1)}>One more blank</a><br/>
+  {if n > 0 then
+       <xml><a link={form (n - 1)}>One fewer blank</a></xml>
+   else
+       <xml/>}
+</body></xml>
+
+fun main () = form 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/subforms.urp	Sun May 03 15:53:29 2009 -0400
@@ -0,0 +1,2 @@
+
+subforms
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/subforms.urs	Sun May 03 15:53:29 2009 -0400
@@ -0,0 +1,1 @@
+val main : unit -> transaction page