changeset 1491:b2ca3e1e5b40

Fixes for detecting pastes and autocompletes for dynamic textboxes
author Adam Chlipala <adam@chlipala.net>
date Fri, 15 Jul 2011 10:02:54 -0400
parents a77fa7e7bb7b
children 175b6d52252d
files lib/js/urweb.js tests/autocomp.ur
diffstat 2 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lib/js/urweb.js	Fri Jul 08 13:33:26 2011 -0400
+++ b/lib/js/urweb.js	Fri Jul 15 10:02:54 2011 -0400
@@ -277,11 +277,13 @@
     return {data : v, dyns : null};
 }
 function sv(s, v) {
-    s.data = v;
+    if (s.data != v) {
+        s.data = v;
 
-    for (var ls = s.dyns; ls; ls = ls.next)
-        if (!ls.dead)
-            populate(ls.data);
+        for (var ls = s.dyns; ls; ls = ls.next)
+            if (!ls.dead)
+                populate(ls.data);
+    }
 }
 function sg(s) {
     return s.data;
@@ -491,7 +493,7 @@
     var x = input(document.createElement("input"), s,
                   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) };
+    x.onkeyup = x.oninput = x.onchange = x.onpropertychange = function() { sv(s, x.value) };
 
     return x;
 }
@@ -545,7 +547,7 @@
     var x = input(document.createElement("textarea"), s,
                   function(x) { return function(v) { if (x.innerHTML != v) x.innerHTML = v; }; });
     x.innerHTML = s.data;
-    x.onkeyup = function() { sv(s, x.value) };
+    x.onkeyup = x.oninput = x.onchange = x.onpropertychange = function() { sv(s, x.value) };
 
     return x;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/autocomp.ur	Fri Jul 15 10:02:54 2011 -0400
@@ -0,0 +1,11 @@
+fun main () : transaction page =
+  a <- source "";
+  b <- source "";
+  return <xml><body>
+    <form>
+      <textbox{#A} source={a}/>
+      <button onclick={x <- get a; set b x}/>
+      <dyn signal={v <- signal a; return <xml>{[v]}</xml>}/>
+      / <dyn signal={v <- signal b; return <xml>{[v]}</xml>}/>
+    </form>
+  </body></xml>