summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-05-29 12:44:31 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2011-05-29 12:44:31 -0400
commitc6b4e9ff771cf8e697ea36dd31230c03cacf5442 (patch)
tree1f5fac0828731fd598a24d7b5361ebc38e203a66
parent3399aef91b4d4684bf2a2935cffde20e80453673 (diff)
Properly handle form textboxes that have sources
-rw-r--r--lib/js/urweb.js7
-rw-r--r--src/monoize.sml8
-rw-r--r--tests/tsource.ur28
-rw-r--r--tests/tsource.urs1
4 files changed, 38 insertions, 6 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index 5a6ce21f..a3ab6fde 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -461,7 +461,8 @@ function dyn(pnode, s) {
populate(x);
}
-function input(x, s, recreate, type) {
+function input(x, s, recreate, type, name) {
+ if (name) x.name = name;
if (type) x.type = type;
x.dead = false;
x.signal = ss(s);
@@ -473,9 +474,9 @@ function input(x, s, recreate, type) {
return x;
}
-function inp(s) {
+function inp(s, name) {
var x = input(document.createElement("input"), s,
- function(x) { return function(v) { if (x.value != v) x.value = v; }; });
+ function(x) { return function(v) { if (x.value != v) x.value = v; }; }, null, name);
x.value = s.data;
x.onkeyup = function() { sv(s, x.value) };
diff --git a/src/monoize.sml b/src/monoize.sml
index 856cd43e..85b9a39e 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -2737,8 +2737,8 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
(L.EFfi ("Basis", "sql_nfunc"), _),
_), _),
_), _),
- _), _),
- _) =>
+ _), _),
+ _) =>
let
val s = (L'.TFfi ("Basis", "string"), loc)
fun sc s = (L'.EPrim (Prim.String s), loc)
@@ -3258,7 +3258,9 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
| SOME (_, src, _) =>
(strcat [str "<script type=\"text/javascript\">inp(exec(",
(L'.EJavaScript (L'.Script, src), loc),
- str "))</script>"],
+ str "), \"",
+ str name,
+ str "\")</script>"],
fm))
| _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
raise Fail "No name passed to textbox tag"))
diff --git a/tests/tsource.ur b/tests/tsource.ur
new file mode 100644
index 00000000..20cb4860
--- /dev/null
+++ b/tests/tsource.ur
@@ -0,0 +1,28 @@
+fun doSubmit r =
+ return <xml>Done {[readError r.Amount1 * readError r.Amount2 * 2.0]}</xml>
+
+fun main () =
+ amount1S <- source "1";
+ amount2S <- source "1";
+ return <xml> <body>
+ <form>
+ <table>
+ <tr><td>Amount1:</td><td><textbox{#Amount1}
+source={amount1S}/></td></tr>
+ <tr><td>Amount2:</td><td><textbox{#Amount2}
+source={amount2S}/></td></tr>
+ <tr><td>Total:</td><td><dyn signal={showTotal amount1S
+amount2S}/></td></tr>
+ </table>
+ <submit value="Buy" action={doSubmit}/>
+ </form>
+ </body>
+</xml>
+
+and showTotal amount1S amount2S =
+ a1 <- signal amount1S;
+ a2 <- signal amount2S;
+ return (case ((read a1), (read a2)) of
+ (None, _) => <xml></xml>
+ | (_, None) => <xml></xml>
+ | (Some a, Some b) => <xml>{[a * b * 2.0]}</xml>)
diff --git a/tests/tsource.urs b/tests/tsource.urs
new file mode 100644
index 00000000..6ac44e0b
--- /dev/null
+++ b/tests/tsource.urs
@@ -0,0 +1 @@
+val main : unit -> transaction page