From 4bc385e41e89022a4488d16d5076efbdadaffdb5 Mon Sep 17 00:00:00 2001 From: Murderlon Date: Tue, 2 Jul 2024 16:43:33 +0200 Subject: [PATCH 1/3] @uppy/form: bring back submit() instead of requestSubmit() --- packages/@uppy/form/src/index.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/@uppy/form/src/index.ts b/packages/@uppy/form/src/index.ts index 9ad700aefe..3bf6b54347 100644 --- a/packages/@uppy/form/src/index.ts +++ b/packages/@uppy/form/src/index.ts @@ -52,12 +52,6 @@ export default class Form extends BasePlugin< form: HTMLFormElement // TODO: make this private (or at least, mark it as readonly) - /** - * Unfortunately Uppy isn't a state machine in which we can guarantee it's - * currently in one state and one state only so we use this completed property which is set on `upload-success'. - */ - #completed = false - constructor(uppy: Uppy, opts?: FormOptions) { super(uppy, { ...defaultOptions, ...opts }) this.type = 'acquirer' @@ -71,25 +65,23 @@ export default class Form extends BasePlugin< } handleUploadStart(): void { - this.#completed = false if (this.opts.getMetaFromForm) { this.getMetaFromForm() } } handleSuccess(result: Result): void { - this.#completed = true if (this.opts.addResultToForm) { this.addResultToForm(result) } if (this.opts.submitOnSuccess) { - this.form.requestSubmit() + this.form.submit() } } handleFormSubmit(ev: Event): void { - if (this.opts.triggerUploadOnSubmit && !this.#completed) { + if (this.opts.triggerUploadOnSubmit) { ev.preventDefault() const elements = toArray((ev.target as HTMLFormElement).elements) const disabledByUppy: HTMLButtonElement[] = [] From 44c5a71d3274e0ebe0afa325a5acc51e9581ac92 Mon Sep 17 00:00:00 2001 From: Murderlon Date: Tue, 2 Jul 2024 17:37:37 +0200 Subject: [PATCH 2/3] Add reportValidity --- packages/@uppy/form/src/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/@uppy/form/src/index.ts b/packages/@uppy/form/src/index.ts index 3bf6b54347..791a3d3538 100644 --- a/packages/@uppy/form/src/index.ts +++ b/packages/@uppy/form/src/index.ts @@ -76,6 +76,9 @@ export default class Form extends BasePlugin< } if (this.opts.submitOnSuccess) { + // When false is returned, cancelable invalid events are fired + // for each invalid child and validation problems are reported to the user. + this.form.reportValidity() this.form.submit() } } From a9e530ec8a2732929f5ae49ca0d39bc749fc2d70 Mon Sep 17 00:00:00 2001 From: Murderlon Date: Tue, 2 Jul 2024 17:40:36 +0200 Subject: [PATCH 3/3] Do not submit when reportValidity is false --- packages/@uppy/form/src/index.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/@uppy/form/src/index.ts b/packages/@uppy/form/src/index.ts index 791a3d3538..27f92c6c4f 100644 --- a/packages/@uppy/form/src/index.ts +++ b/packages/@uppy/form/src/index.ts @@ -76,10 +76,12 @@ export default class Form extends BasePlugin< } if (this.opts.submitOnSuccess) { - // When false is returned, cancelable invalid events are fired - // for each invalid child and validation problems are reported to the user. - this.form.reportValidity() - this.form.submit() + // Returns true if the element's child controls satisfy their validation constraints. + // When false is returned, cancelable invalid events are fired for each invalid child + // and validation problems are reported to the user. + if (this.form.reportValidity()) { + this.form.submit() + } } }