Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client: switch widget: prevent the check box to become out of sync with the switch toggle status
Adorian Doran8bdc5c9fead3
diff --git a/src/public/app/widgets/switch.js b/src/public/app/widgets/switch.jsindex 00489b3d4a..7f422b79c5 100644--- a/src/public/app/widgets/switch.js+++ b/src/public/app/widgets/switch.js@@ -46,6 +46,10 @@ const TPL = `.switch-widget .switch-button.on {background: green !important;}++ .switch-widget input[type="checkbox"] {+ pointer-events: none;+ }</style><div class="switch-widget">@@ -75,7 +79,13 @@ export default class SwitchWidget extends NoteContextAwareWidget {this.$switchButton = this.$widget.find(".switch-button");this.$switchToggle = this.$widget.find(".switch-toggle");- this.$switchToggle.on("click", () => this.toggle(!this.currentState));+ this.$switchToggle.on("click", (e) => {+ this.toggle(!this.currentState);++ // Prevent the check box from being toggled by the click, the value of the check box+ // should be set exclusively by the 'isToggled' property setter.+ e.preventDefault();+ });this.$switchName = this.$widget.find(".switch-name");@@ -103,6 +113,7 @@ export default class SwitchWidget extends NoteContextAwareWidget {this.$switchButton.toggleClass("on", this.currentState);this.$switchToggle.prop("checked", this.currentState);+ console.log(this.currentState);if (this.currentState) {this.$switchName.text(this.switchOffName);