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