]> BookStack Code Mirror - bookstack/blob - resources/js/components/submit-on-change.js
aeacae23213bd96b94290ed9ab6a4e9e131a4b78
[bookstack] / resources / js / components / submit-on-change.js
1 /**
2  * Submit on change
3  * Simply submits a parent form when this input is changed.
4  * @extends {Component}
5  */
6 class SubmitOnChange {
7
8     setup() {
9         this.filter = this.$opts.filter;
10
11         this.$el.addEventListener('change', (event) => {
12
13             if (this.filter && !event.target.matches(this.filter)) {
14                 return;
15             }
16
17             const form = this.$el.closest('form');
18             if (form) {
19                 form.submit();
20             }
21         });
22     }
23
24 }
25
26 export default SubmitOnChange;