From 04f51929b9a5849e4d4a922cd62ec55e7da30d14 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 3 May 2009 15:53:29 -0400 Subject: subforms demo --- demo/prose | 4 ++++ demo/subforms.ur | 43 +++++++++++++++++++++++++++++++++++++++++++ demo/subforms.urp | 2 ++ demo/subforms.urs | 1 + 4 files changed, 50 insertions(+) create mode 100644 demo/subforms.ur create mode 100644 demo/subforms.urp create mode 100644 demo/subforms.urs (limited to 'demo') diff --git a/demo/prose b/demo/prose index 3646bfb9..a5935bb9 100644 --- a/demo/prose +++ b/demo/prose @@ -80,6 +80,10 @@ upload.urp

In the .urp 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.

+subforms.urp + +

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 <subforms> and <entry> 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.

+ listShop.urp

This example shows off algebraic datatypes, parametric polymorphism, and functors.

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 + [] => + | r :: ls => +
  • {[r.Num]} = {[r.Text]}
  • + {sub' ls} +
    + in + return + {sub' r.Lines} + + end + +fun subforms n = + if n <= 0 then + + else + + + +
  • {[n]}:
  • +
    + {subforms (n - 1)} +
    + +fun form n = return +
    + + {subforms n} + + + + + One more blank
    + {if n > 0 then + One fewer blank + else + } + + +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 -- cgit v1.2.3