2022-10-27 17:07:18 +02:00
|
|
|
import { ApplicationController } from './application_controller';
|
|
|
|
import { toggle } from '@utils';
|
2022-11-04 12:22:39 +01:00
|
|
|
const AUTOSUBMIT_DEBOUNCE_DELAY = 5000;
|
2022-10-27 17:07:18 +02:00
|
|
|
|
|
|
|
export class AutosubmitController extends ApplicationController {
|
|
|
|
static targets = ['form', 'spinner'];
|
|
|
|
|
|
|
|
declare readonly formTarget: HTMLFormElement;
|
|
|
|
declare readonly spinnerTarget: HTMLElement;
|
|
|
|
|
|
|
|
submit() {
|
|
|
|
this.formTarget.requestSubmit();
|
|
|
|
}
|
2022-11-04 12:22:39 +01:00
|
|
|
|
|
|
|
debouncedSubmit() {
|
|
|
|
this.debounce(this.submit, AUTOSUBMIT_DEBOUNCE_DELAY);
|
|
|
|
}
|
|
|
|
|
2022-10-27 17:07:18 +02:00
|
|
|
connect() {
|
|
|
|
this.onGlobal('turbo:submit-start', () => {
|
|
|
|
toggle(this.spinnerTarget);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|