summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--demo/prose4
-rw-r--r--demo/subforms.ur43
-rw-r--r--demo/subforms.urp2
-rw-r--r--demo/subforms.urs1
4 files changed, 50 insertions, 0 deletions
diff --git a/demo/prose b/demo/prose
index 3646bfb9..a5935bb9 100644
--- a/demo/prose
+++ b/demo/prose
@@ -80,6 +80,10 @@ upload.urp
<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>
diff --git a/demo/subforms.ur b/demo/subforms.ur
new file mode 100644
index 00000000..71bd1e82
--- /dev/null
+++ b/demo/subforms.ur
@@ -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
diff --git a/demo/subforms.urp b/demo/subforms.urp
new file mode 100644
index 00000000..d2ac98ee
--- /dev/null
+++ b/demo/subforms.urp
@@ -0,0 +1,2 @@
+
+subforms
diff --git a/demo/subforms.urs b/demo/subforms.urs
new file mode 100644
index 00000000..6ac44e0b
--- /dev/null
+++ b/demo/subforms.urs
@@ -0,0 +1 @@
+val main : unit -> transaction page