From 773c309baa825ae91a9d86358785f8c3056bad8f Mon Sep 17 00:00:00 2001 From: Artyom Shalkhakov Date: Tue, 21 Feb 2017 16:20:27 +0000 Subject: Button: disabled attribute; allowing number entry using HTML5 widgets --- lib/js/urweb.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'lib/js/urweb.js') 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) { -- cgit v1.2.3