diff --git a/app/javascript/controllers/autosave_controller.ts b/app/javascript/controllers/autosave_controller.ts index f3a4b7d1f..0be1bf0cf 100644 --- a/app/javascript/controllers/autosave_controller.ts +++ b/app/javascript/controllers/autosave_controller.ts @@ -75,9 +75,11 @@ export class AutosaveController extends ApplicationController { if (!target.disabled) { if (target.type == 'file') { if (target.dataset.autoAttachUrl && target.files?.length) { + this.globalDispatch('autosave:input'); this.enqueueAutouploadRequest(target, target.files[0]); } } else if (target.type == 'hidden') { + this.globalDispatch('autosave:input'); // In React comboboxes we dispatch a "change" event on hidden inputs to trigger autosave. // We want to debounce them. this.debounce(this.enqueueAutosaveRequest, AUTOSAVE_DEBOUNCE_DELAY); @@ -85,6 +87,7 @@ export class AutosaveController extends ApplicationController { isSelectElement(target) || isCheckboxOrRadioInputElement(target) ) { + this.globalDispatch('autosave:input'); // Wait next tick so champs having JS can interact // with form elements before extracting form data. setTimeout(() => { @@ -103,6 +106,7 @@ export class AutosaveController extends ApplicationController { target.getAttribute('role') != 'combobox' && isTextInputElement(target) ) { + this.globalDispatch('autosave:input'); this.debounce(this.enqueueAutosaveRequest, AUTOSAVE_DEBOUNCE_DELAY); this.showConditionnalSpinner(target); diff --git a/app/javascript/controllers/autosave_submit_controller.ts b/app/javascript/controllers/autosave_submit_controller.ts index 9f4021ef1..94e9e78d4 100644 --- a/app/javascript/controllers/autosave_submit_controller.ts +++ b/app/javascript/controllers/autosave_submit_controller.ts @@ -8,7 +8,7 @@ export class AutosaveSubmitController extends ApplicationController { #buttonText?: string; connect(): void { - this.onGlobal('autosave:enqueue', () => this.didEnqueue()); + this.onGlobal('autosave:input', () => this.didInput()); this.onGlobal('autosave:end', () => this.didSucceed()); this.onGlobal('autosave:error', () => this.didFail()); this.on('click', (event) => this.onClick(event)); @@ -23,7 +23,7 @@ export class AutosaveSubmitController extends ApplicationController { } } - private didEnqueue() { + private didInput() { this.#isSaving = true; this.#shouldSubmit = false; }