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