From d7f170b57a37a579bdd637ecd3309faf93b5b2e6 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 24 Jan 2023 09:22:04 +0100 Subject: [PATCH] fix(combobox): let direct upload finish before submitting form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quand un form pour lequel on intercepte le submit a un direct upload, on laisse le direct upload gérer le submit manuellement pour attendre la fin de l'upload ; autrement le form est parfois soumis sans la référence au fichier, ce qui provoque des erreurs rails `InvalidSignature`. --- app/javascript/components/shared/hooks.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/javascript/components/shared/hooks.ts b/app/javascript/components/shared/hooks.ts index f91ed8d69..dd000143f 100644 --- a/app/javascript/components/shared/hooks.ts +++ b/app/javascript/components/shared/hooks.ts @@ -15,7 +15,15 @@ export function useDeferredSubmit(input?: HTMLInputElement): { const interceptFormSubmit = (event: Event) => { event.preventDefault(); runCallback(); - form.submit(); + + if ( + !Array.from(form.elements).some((e) => + e.hasAttribute('data-direct-upload-url') + ) + ) { + form.submit(); + } + // else: form will be submitted by diret upload once file have been uploaded }; calledRef.current = false; form.addEventListener('submit', interceptFormSubmit);