X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/07b889547d28e68e5fc8f923c166bd607da17ad7..refs/pull/1626/head:/resources/assets/js/components/toggle-switch.js diff --git a/resources/assets/js/components/toggle-switch.js b/resources/assets/js/components/toggle-switch.js index 3be67d5dc..b9b96afc5 100644 --- a/resources/assets/js/components/toggle-switch.js +++ b/resources/assets/js/components/toggle-switch.js @@ -6,12 +6,16 @@ class ToggleSwitch { this.input = elem.querySelector('input[type=hidden]'); this.checkbox = elem.querySelector('input[type=checkbox]'); - this.checkbox.addEventListener('change', this.onClick.bind(this)); + this.checkbox.addEventListener('change', this.stateChange.bind(this)); } - onClick(event) { - let checked = this.checkbox.checked; - this.input.value = checked ? 'true' : 'false'; + stateChange() { + this.input.value = (this.checkbox.checked ? 'true' : 'false'); + + // Dispatch change event from hidden input so they can be listened to + // like a normal checkbox. + const changeEvent = new Event('change'); + this.input.dispatchEvent(changeEvent); } }