summaryrefslogtreecommitdiff
path: root/lib/js/urweb.js
diff options
context:
space:
mode:
authorGravatar Artyom Shalkhakov <artyom.shalkhakov@gmail.com>2017-02-21 16:20:27 +0000
committerGravatar Artyom Shalkhakov <artyom.shalkhakov@gmail.com>2017-02-21 16:20:27 +0000
commit773c309baa825ae91a9d86358785f8c3056bad8f (patch)
tree81a9b5e32107d50452785f5b256e56285bcb75f3 /lib/js/urweb.js
parent59454c9766685b381603aaf116bb43a9515dbdba (diff)
Button: disabled attribute; allowing number entry using HTML5 widgets
Diffstat (limited to 'lib/js/urweb.js')
-rw-r--r--lib/js/urweb.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index 222a8322..ebe192ca 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -1127,6 +1127,23 @@ function inpt(type, s, name) {
return x;
}
+function inpt_float(type, s, name) {
+ if (suspendScripts)
+ return;
+
+ var filterFloat = function(value) {
+ if (/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/
+ .test(value))
+ return Number(value);
+ return null;
+ }
+ var x = input(document.createElement("input"), s, function(x) { return function(v) { if (x.value != v) x.value = v; }; }, type, name);
+ x.value = s.data;
+ x.onkeyup = x.oninput = x.onchange = x.onpropertychange = function() { sv(s, filterFloat(x.value)) };
+
+ return x;
+}
+
function inp(s, name) {
return inpt("text", s, name);
@@ -1157,11 +1174,11 @@ function color(s, name) {
}
function number(s, name) {
- return inpt("number", s, name);
+ return inpt_float("number", s, name);
}
function range(s, name) {
- return inpt("range", s, name);
+ return inpt_float("range", s, name);
}
function date(s, name) {