fix(combobox): let direct upload finish before submitting form

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`.
This commit is contained in:
Colin Darie 2023-01-24 09:22:04 +01:00
parent 4e0f83aad6
commit d7f170b57a

View file

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