SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking. svghmi
authorEdouard Tisserant
Thu, 27 Aug 2020 09:59:35 +0200
branchsvghmi
changeset 3042 ed43facc7137
parent 3041 de4503de2f8c
child 3043 d7b009e49e87
SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking.
svghmi/gen_index_xhtml.xslt
svghmi/widget_keypad.ysl2
--- a/svghmi/gen_index_xhtml.xslt	Wed Aug 26 14:27:54 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt	Thu Aug 27 09:59:35 2020 +0200
@@ -1510,8 +1510,6 @@
 </xsl:text>
     <xsl:text>        if (this.active_style &amp;&amp; this.inactive_style) {
 </xsl:text>
-    <xsl:text>            console.log("pressedi...")
-</xsl:text>
     <xsl:text>            this.active_elt.setAttribute("style", this.active_style);
 </xsl:text>
     <xsl:text>            this.inactive_elt.setAttribute("style", "display:none");
@@ -1520,8 +1518,6 @@
 </xsl:text>
     <xsl:text>        this.apply_hmi_value(0, 1);
 </xsl:text>
-    <xsl:text>        console.log("pressed")
-</xsl:text>
     <xsl:text>        // TODO inhibit all mouse/touch events except mouse up (in other word grab cursor)
 </xsl:text>
     <xsl:text>    }
@@ -1532,8 +1528,6 @@
 </xsl:text>
     <xsl:text>        if (this.active_style &amp;&amp; this.inactive_style) {
 </xsl:text>
-    <xsl:text>            console.log("unpressedi...")
-</xsl:text>
     <xsl:text>            this.active_elt.setAttribute("style", "display:none");
 </xsl:text>
     <xsl:text>            this.inactive_elt.setAttribute("style", this.inactive_style);
@@ -1542,8 +1536,6 @@
 </xsl:text>
     <xsl:text>        this.apply_hmi_value(0, 0);
 </xsl:text>
-    <xsl:text>        console.log("unpressed")
-</xsl:text>
     <xsl:text>        // TODO release inhibited events 
 </xsl:text>
     <xsl:text>    }
@@ -3403,8 +3395,6 @@
 </xsl:text>
     <xsl:text>            .then(res =&gt; res.json())
 </xsl:text>
-    <xsl:text>            .then(function(res){console.log(res);return res;})
-</xsl:text>
     <xsl:text>            .then(this.spread_json_data.bind(this));
 </xsl:text>
     <xsl:text>
@@ -4115,13 +4105,15 @@
 </xsl:text>
     <xsl:text>         let coercedval = (typeof this.initial) == "number" ? Number(this.editstr) : this.editstr;
 </xsl:text>
-    <xsl:text>         if(isNaN(coercedval)){
+    <xsl:text>         if(typeof coercedval == 'number' &amp;&amp; isNaN(coercedval)){
+</xsl:text>
+    <xsl:text>             // revert to initial so it explicitely shows input was ignored
 </xsl:text>
     <xsl:text>             this.editstr = String(this.initial);
 </xsl:text>
     <xsl:text>             this.update();
 </xsl:text>
-    <xsl:text>         } else { // revert to initial so it explicitely shows input was ignored
+    <xsl:text>         } else { 
 </xsl:text>
     <xsl:text>             let callback_obj = this.result_callback_obj;
 </xsl:text>
--- a/svghmi/widget_keypad.ysl2	Wed Aug 26 14:27:54 2020 +0200
+++ b/svghmi/widget_keypad.ysl2	Thu Aug 27 09:59:35 2020 +0200
@@ -89,10 +89,11 @@
 
          on_Enter_click() {
              let coercedval = (typeof this.initial) == "number" ? Number(this.editstr) : this.editstr;
-             if(isNaN(coercedval)){
+             if(typeof coercedval == 'number' && isNaN(coercedval)){
+                 // revert to initial so it explicitely shows input was ignored
                  this.editstr = String(this.initial);
                  this.update();
-             } else { // revert to initial so it explicitely shows input was ignored
+             } else { 
                  let callback_obj = this.result_callback_obj;
                  end_modal.call(this);
                  callback_obj.edit_callback(coercedval);