2023-04-18 17:20:02 -04:00
|
|
|
import {Component} from './component';
|
2022-11-15 11:04:46 -05:00
|
|
|
|
2020-09-19 07:06:45 -04:00
|
|
|
/**
|
|
|
|
* Submit on change
|
|
|
|
* Simply submits a parent form when this input is changed.
|
|
|
|
*/
|
2022-11-15 11:04:46 -05:00
|
|
|
export class SubmitOnChange extends Component {
|
2020-09-19 07:06:45 -04:00
|
|
|
|
|
|
|
setup() {
|
2021-08-04 15:48:23 -04:00
|
|
|
this.filter = this.$opts.filter;
|
|
|
|
|
2023-04-18 17:20:02 -04:00
|
|
|
this.$el.addEventListener('change', event => {
|
2021-08-04 15:48:23 -04:00
|
|
|
if (this.filter && !event.target.matches(this.filter)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-19 07:06:45 -04:00
|
|
|
const form = this.$el.closest('form');
|
|
|
|
if (form) {
|
|
|
|
form.submit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-18 17:20:02 -04:00
|
|
|
}
|