diff --git a/packages/@uppy/form/src/index.ts b/packages/@uppy/form/src/index.ts index 9ad700aefe..27f92c6c4f 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,28 @@ 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() + // 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() + } } } 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[] = []