-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@uppy/form: bring back submit() instead of requestSubmit() #5299
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Diff output filesdiff --git a/packages/@uppy/form/lib/index.js b/packages/@uppy/form/lib/index.js
index 3f1d23e..a1f8cbb 100644
--- a/packages/@uppy/form/lib/index.js
+++ b/packages/@uppy/form/lib/index.js
@@ -1,13 +1,3 @@
-function _classPrivateFieldLooseBase(receiver, privateKey) {
- if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
- throw new TypeError("attempted to use private field on non-instance");
- }
- return receiver;
-}
-var id = 0;
-function _classPrivateFieldLooseKey(name) {
- return "__private_" + id++ + "_" + name;
-}
import BasePlugin from "@uppy/core/lib/BasePlugin.js";
import findDOMElement from "@uppy/utils/lib/findDOMElement";
import toArray from "@uppy/utils/lib/toArray";
@@ -30,17 +20,12 @@ function assertHTMLFormElement(input) {
}
return input;
}
-var _completed = _classPrivateFieldLooseKey("completed");
export default class Form extends BasePlugin {
constructor(uppy, opts) {
super(uppy, {
...defaultOptions,
...opts,
});
- Object.defineProperty(this, _completed, {
- writable: true,
- value: false,
- });
this.type = "acquirer";
this.id = this.opts.id || "Form";
this.handleFormSubmit = this.handleFormSubmit.bind(this);
@@ -50,22 +35,22 @@ export default class Form extends BasePlugin {
this.getMetaFromForm = this.getMetaFromForm.bind(this);
}
handleUploadStart() {
- _classPrivateFieldLooseBase(this, _completed)[_completed] = false;
if (this.opts.getMetaFromForm) {
this.getMetaFromForm();
}
}
handleSuccess(result) {
- _classPrivateFieldLooseBase(this, _completed)[_completed] = true;
if (this.opts.addResultToForm) {
this.addResultToForm(result);
}
if (this.opts.submitOnSuccess) {
- this.form.requestSubmit();
+ if (this.form.reportValidity()) {
+ this.form.submit();
+ }
}
}
handleFormSubmit(ev) {
- if (this.opts.triggerUploadOnSubmit && !_classPrivateFieldLooseBase(this, _completed)[_completed]) {
+ if (this.opts.triggerUploadOnSubmit) {
ev.preventDefault();
const elements = toArray(ev.target.elements);
const disabledByUppy = []; |
Should we use |
aduh95
approved these changes
Jul 2, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we should add reportValidity
to the list of things one needs to polyfill in order to use Uppy with e.g. IE, but we didn't for requestSubmit
and no one complained, so I guess we're fine.
This was referenced Jul 2, 2024
github-actions bot
added a commit
that referenced
this pull request
Jul 2, 2024
| Package | Version | Package | Version | | ---------------------- | ------- | ---------------------- | ------- | | @uppy/companion | 4.15.0 | @uppy/drag-drop | 3.1.1 | | @uppy/companion-client | 3.8.2 | @uppy/form | 3.2.2 | | @uppy/core | 3.13.1 | uppy | 3.27.2 | - @uppy/form: do not emit `'submit'` event more than once (Merlijn Vos / #5299) - @uppy/companion: add `s3.forcePathStyle` option (Nadeem Reinhardt / #5066) - meta: fix broken workflow status badges in README (Alexander Zaytsev / #5298) - @uppy/core: add `clearUploadedFiles` to type definition (Augustine Smith / #5295) - @uppy/companion: add `oauthOrigin` option (Antoine du Hamel / #5297) - meta: add dark-mode Transloadit logo in README (Alexander Zaytsev / #5291) - docs,@uppy/drag-drop: `uppy.io/docs` - fix typos/broken links (Evgenia Karunus / #5296) - meta: Bump docker/build-push-action from 6.1.0 to 6.2.0 (dependabot[bot] / #5290)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #5278
Sometime ago I switched our
form.submit()
toform.requestSubmit()
(#4852) so that we first trigger form validation and only submit when there are no errors, whilesubmit()
always submits.Unfortunately I didn't realize that unlike
submit()
requestSubmit()
triggers the'submit'
event again, which caused a loop. This was fixed in #5058.Unfortunately I didn't realize again that
requestSubmit()
no longer works afterevent.preventDefault()
, which we need for thetriggerUploadOnSubmit
in order to hold off the submit to upload with Uppy. If you also enablesubmitOnSuccess
, then once we reachrequestSubmit()
it no longer works because ofpreventDefault()
.AFAIK for these specific set of conditions we support in Uppy, we can't reliably use
requestSubmit
so I'm puttingsubmit
back.