aboutsummaryrefslogtreecommitdiffhomepage
path: root/demo
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-05-03 16:00:43 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-05-03 16:00:43 -0400
commit011a2d458a677c5db5c2fdf0684eeecaf688d6d9 (patch)
tree102fd827152c2277b58565cbe1692e2d60cd56e9 /demo
parent04f51929b9a5849e4d4a922cd62ec55e7da30d14 (diff)
crud3 demo
Diffstat (limited to 'demo')
-rw-r--r--demo/crud3.ur27
-rw-r--r--demo/crud3.urp5
-rw-r--r--demo/prose6
3 files changed, 38 insertions, 0 deletions
diff --git a/demo/crud3.ur b/demo/crud3.ur
new file mode 100644
index 00000000..efc6c06e
--- /dev/null
+++ b/demo/crud3.ur
@@ -0,0 +1,27 @@
+table t : {Id : int, Text : string}
+ PRIMARY KEY Id
+
+open Crud.Make(struct
+ val tab = t
+
+ val title = "Crud3"
+
+ val cols = {Text = {Nam = "Text",
+ Show = txt,
+ Widget = (fn (nm :: Name) => <xml>
+ <subform{nm}>
+ <textbox{#A}/>
+ <textbox{#B}/>
+ </subform>
+ </xml>),
+ WidgetPopulated = (fn (nm :: Name) s => <xml>
+ <subform{nm}>
+ <textbox{#A} value={s}/>
+ <textbox{#B}/>
+ </subform>
+ </xml>),
+ Parse = (fn p => p.A ^ p.B),
+ Inject = _
+ }
+ }
+ end)
diff --git a/demo/crud3.urp b/demo/crud3.urp
new file mode 100644
index 00000000..cc3be2f6
--- /dev/null
+++ b/demo/crud3.urp
@@ -0,0 +1,5 @@
+database dbname=test
+sql crud3.sql
+
+crud
+crud3
diff --git a/demo/prose b/demo/prose
index a5935bb9..0c443692 100644
--- a/demo/prose
+++ b/demo/prose
@@ -231,6 +231,12 @@ crud2.urp
<p>This example shows another application of <tt>Crud.Make</tt>. We mix one standard column with one customized column. We write an underscore for the <tt>Inject</tt> field of meta-data, since the type class facility can infer that witness.</p>
+crud3.urp
+
+<p>One thing that is unclear from the previous examples is how to provide more complex, multi-input widgets for taking input meant for particular fields. The signature of <tt>Crud.Make</tt> forces every widget to define exactly one input. The <tt>&lt;subform&gt;</tt> tag, the simpler cousin of the <tt>&lt;subforms&gt;</tt> tag that we saw earlier, provides a fix for this problem. Via <tt>&lt;subform&gt;</tt>, an arbitrary form can be turned into a single record-valued input.</p>
+
+<p>We use that possibility here to define a silly widget for a <tt>string</tt> column, which concatenates the values entered into two different textboxes.</p>
+
alert.urp
<p>Ur/Web makes it easy to write code whose execution should be distributed between the web server and client web browsers. Server-side code is compiled to efficient native code, and client-side code is compiled to JavaScript. Ur/Web programmers don't need to worry about these details, because the language and standard library provide a uniform ML-like interface for the whole process.</p>