fix(dossier): delay submit to autosave end

This commit is contained in:
Paul Chavard 2023-10-10 18:14:09 +02:00
parent 5f6fb3013d
commit de9d3501b5
2 changed files with 6 additions and 2 deletions

View file

@ -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);

View file

@ -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;
}