]> BookStack Code Mirror - bookstack/blob - resources/js/components/toggle-switch.js
Comments: Added reference marker to comments
[bookstack] / resources / js / components / toggle-switch.js
1 import {Component} from './component';
2
3 export class ToggleSwitch extends Component {
4
5     setup() {
6         this.input = this.$el.querySelector('input[type=hidden]');
7         this.checkbox = this.$el.querySelector('input[type=checkbox]');
8
9         this.checkbox.addEventListener('change', this.stateChange.bind(this));
10     }
11
12     stateChange() {
13         this.input.value = (this.checkbox.checked ? 'true' : 'false');
14
15         // Dispatch change event from hidden input so they can be listened to
16         // like a normal checkbox.
17         const changeEvent = new Event('change');
18         this.input.dispatchEvent(changeEvent);
19     }
20
21 }