# HG changeset patch # User Adam Chlipala # Date 1241380409 14400 # Node ID 0084af7af35a47dc543354eb1305aa6d9f160009 # Parent 7394368a5cadc7bac9ff07028e44e1a701513fb2 subforms demo diff -r 7394368a5cad -r 0084af7af35a demo/prose --- 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 @@

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 -r 7394368a5cad -r 0084af7af35a demo/subforms.ur --- /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 + [] => + | 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 -r 7394368a5cad -r 0084af7af35a demo/subforms.urp --- /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 diff -r 7394368a5cad -r 0084af7af35a demo/subforms.urs --- /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