svghmi/widget_tooglebutton.ysl2
branchsvghmi
changeset 3056 827bf284feec
parent 3024 0a9f6f29b7dd
child 3059 e0db3f6a5f39
--- a/svghmi/widget_tooglebutton.ysl2	Tue Aug 18 11:42:28 2020 +0200
+++ b/svghmi/widget_tooglebutton.ysl2	Wed Sep 16 09:41:52 2020 +0200
@@ -10,19 +10,28 @@
         inactive_style = undefined;
 
         dispatch(value) {
-            this.state = value;
-            if (this.state) {
-                this.active_elt.setAttribute("style", this.active_style);
-                this.inactive_elt.setAttribute("style", "display:none");
-                this.state = 0;
-            } else {
-                this.inactive_elt.setAttribute("style", this.inactive_style);
-                this.active_elt.setAttribute("style", "display:none");
-                this.state = 1;
+            if(this.state != value){
+                this.state = value;
+                if (this.state) {
+                    this.active_elt.setAttribute("style", this.active_style);
+                    this.inactive_elt.setAttribute("style", "display:none");
+                } else {
+                    this.inactive_elt.setAttribute("style", this.inactive_style);
+                    this.active_elt.setAttribute("style", "display:none");
+                }
             }
         }
 
         on_click(evt) {
+            if (this.state) {
+                this.inactive_elt.setAttribute("style", this.inactive_style);
+                this.active_elt.setAttribute("style", "display:none");
+                this.state = 0;
+            } else {
+                this.active_elt.setAttribute("style", this.active_style);
+                this.inactive_elt.setAttribute("style", "display:none");
+                this.state = 1;
+            }
             this.apply_hmi_value(0, this.state);
         }
 
@@ -30,6 +39,8 @@
             this.active_style = this.active_elt.style.cssText;
             this.inactive_style = this.inactive_elt.style.cssText;
             this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
+            this.inactive_elt.setAttribute("style", this.inactive_style);
+            this.active_elt.setAttribute("style", "display:none");
         }
     }
     ||