# HG changeset patch
# User Edouard Tisserant
# Date 1615803924 -3600
# Node ID c173452bf894c91955e10e8b389a558433167039
# Parent  ba8ff21fd82b7a7dc3eba8f08fb09ac57bbed940
SVGHMI: Fixed problems happening when value is higher than maximum or lower than minimum in Input widget. "max" and "min" string was getting into keypad text field, was not diplayed systematically, and was staying forever sometime.

diff -r ba8ff21fd82b -r c173452bf894 svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt	Fri Mar 12 15:12:38 2021 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Mon Mar 15 11:25:24 2021 +0100
@@ -4422,11 +4422,37 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:text>         is_inhibited = false;
+</xsl:text>
+    <xsl:text>         alert(msg){
+</xsl:text>
+    <xsl:text>             this.is_inhibited = true;
+</xsl:text>
+    <xsl:text>             this.display = msg;
+</xsl:text>
+    <xsl:text>             setTimeout(() =&gt; this.stopalert(), 1000);
+</xsl:text>
+    <xsl:text>             this.request_animate();
+</xsl:text>
+    <xsl:text>         }
+</xsl:text>
+    <xsl:text>
+</xsl:text>
+    <xsl:text>         stopalert(){
+</xsl:text>
+    <xsl:text>             this.is_inhibited = false;
+</xsl:text>
+    <xsl:text>             this.display = this.last_value;
+</xsl:text>
+    <xsl:text>             this.request_animate();
+</xsl:text>
+    <xsl:text>         }
+</xsl:text>
+    <xsl:text>
+</xsl:text>
     <xsl:text>         overshot(new_val, max) {
 </xsl:text>
-    <xsl:text>             this.last_display = "max: "+max;
-</xsl:text>
-    <xsl:text>             this.request_animate();
+    <xsl:text>             this.alert("max");
 </xsl:text>
     <xsl:text>         }
 </xsl:text>
@@ -4434,9 +4460,7 @@
 </xsl:text>
     <xsl:text>         undershot(new_val, min) {
 </xsl:text>
-    <xsl:text>             this.last_display = "min: "+min;
-</xsl:text>
-    <xsl:text>             this.request_animate();
+    <xsl:text>             this.alert("min");
 </xsl:text>
     <xsl:text>         }
 </xsl:text>
@@ -4480,19 +4504,25 @@
     <xsl:if test="$have_value or $have_edit">
       <xsl:choose>
         <xsl:when test="count(arg) = 1">
-          <xsl:text>        this.last_display = vsprintf("</xsl:text>
+          <xsl:text>        this.last_value = vsprintf("</xsl:text>
           <xsl:value-of select="arg[1]/@value"/>
           <xsl:text>", [value]);
 </xsl:text>
         </xsl:when>
         <xsl:otherwise>
-          <xsl:text>        this.last_display = value;
+          <xsl:text>        this.last_value = value;
 </xsl:text>
         </xsl:otherwise>
       </xsl:choose>
-    </xsl:if>
-    <xsl:if test="$have_value">
-      <xsl:text>        this.request_animate();
+      <xsl:text>        if(!this.is_inhibited){
+</xsl:text>
+      <xsl:text>            this.display = this.last_value;
+</xsl:text>
+      <xsl:if test="$have_value">
+        <xsl:text>            this.request_animate();
+</xsl:text>
+      </xsl:if>
+      <xsl:text>        }
 </xsl:text>
     </xsl:if>
     <xsl:text>    },
@@ -4500,7 +4530,7 @@
     <xsl:if test="$have_value">
       <xsl:text>    animate: function(){
 </xsl:text>
-      <xsl:text>        this.value_elt.textContent = String(this.last_display);
+      <xsl:text>        this.value_elt.textContent = String(this.display);
 </xsl:text>
       <xsl:text>    },
 </xsl:text>
@@ -4512,7 +4542,7 @@
       <xsl:value-of select="path/@value"/>
       <xsl:text>", "</xsl:text>
       <xsl:value-of select="path/@type"/>
-      <xsl:text>", this, this.last_display);
+      <xsl:text>", this, this.last_value);
 </xsl:text>
       <xsl:if test="$have_value">
         <xsl:text>        this.value_elt.style.pointerEvents = "none";
diff -r ba8ff21fd82b -r c173452bf894 svghmi/widget_input.ysl2
--- a/svghmi/widget_input.ysl2	Fri Mar 12 15:12:38 2021 +0100
+++ b/svghmi/widget_input.ysl2	Mon Mar 15 11:25:24 2021 +0100
@@ -10,14 +10,26 @@
              this.apply_hmi_value(0, new_val);
          }
 
-         overshot(new_val, max) {
-             this.last_display = "max: "+max;
+         is_inhibited = false;
+         alert(msg){
+             this.is_inhibited = true;
+             this.display = msg;
+             setTimeout(() => this.stopalert(), 1000);
              this.request_animate();
          }
 
+         stopalert(){
+             this.is_inhibited = false;
+             this.display = this.last_value;
+             this.request_animate();
+         }
+
+         overshot(new_val, max) {
+             this.alert("max");
+         }
+
          undershot(new_val, min) {
-             this.last_display = "min: "+min;
-             this.request_animate();
+             this.alert("min");
          }
 
 
@@ -45,28 +57,31 @@
     if "$have_value or $have_edit" {
         choose{
             when "count(arg) = 1" {
-    |         this.last_display = vsprintf("«arg[1]/@value»", [value]);
+    |         this.last_value = vsprintf("«arg[1]/@value»", [value]);
             }
             otherwise {
-    |         this.last_display = value;
+    |         this.last_value = value;
             }
         }
+    |         if(!this.is_inhibited){
+    |             this.display = this.last_value;
+    if "$have_value" {
+    |             this.request_animate();
     }
-    if "$have_value" {
-    |         this.request_animate();
+    |         }
     }
     |     },
 
     if "$have_value" {
     |     animate: function(){
-    |         this.value_elt.textContent = String(this.last_display);
+    |         this.value_elt.textContent = String(this.display);
     |     },
     }
 
     |     init: function() {
 
     if "$have_edit" {
-    |         this.edit_elt.onclick = () => edit_value("«path/@value»", "«path/@type»", this, this.last_display);
+    |         this.edit_elt.onclick = () => edit_value("«path/@value»", "«path/@type»", this, this.last_value);
         if "$have_value" {
     |         this.value_elt.style.pointerEvents = "none";
         }