@uppy/form
Advanced tools
Comparing version 3.2.1 to 3.2.2
# @uppy/form | ||
## 3.2.2 | ||
Released: 2024-07-02 | ||
Included in: Uppy v3.27.2 | ||
- @uppy/form: do not emit `'submit'` event more than once (Merlijn Vos / #5299) | ||
## 3.2.1 | ||
@@ -4,0 +11,0 @@ |
@@ -1,4 +0,1 @@ | ||
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'; | ||
@@ -14,3 +11,3 @@ import findDOMElement from '@uppy/utils/lib/findDOMElement'; | ||
const packageJson = { | ||
"version": "3.2.1" | ||
"version": "3.2.2" | ||
}; | ||
@@ -32,4 +29,5 @@ const defaultOptions = { | ||
} | ||
var _completed = /*#__PURE__*/_classPrivateFieldLooseKey("completed"); | ||
export default class Form extends BasePlugin { | ||
// TODO: make this private (or at least, mark it as readonly) | ||
constructor(uppy, opts) { | ||
@@ -40,11 +38,2 @@ super(uppy, { | ||
}); | ||
// 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'. | ||
*/ | ||
Object.defineProperty(this, _completed, { | ||
writable: true, | ||
value: false | ||
}); | ||
this.type = 'acquirer'; | ||
@@ -59,3 +48,2 @@ this.id = this.opts.id || 'Form'; | ||
handleUploadStart() { | ||
_classPrivateFieldLooseBase(this, _completed)[_completed] = false; | ||
if (this.opts.getMetaFromForm) { | ||
@@ -66,3 +54,2 @@ this.getMetaFromForm(); | ||
handleSuccess(result) { | ||
_classPrivateFieldLooseBase(this, _completed)[_completed] = true; | ||
if (this.opts.addResultToForm) { | ||
@@ -72,7 +59,12 @@ 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) { | ||
if (this.opts.triggerUploadOnSubmit && !_classPrivateFieldLooseBase(this, _completed)[_completed]) { | ||
if (this.opts.triggerUploadOnSubmit) { | ||
ev.preventDefault(); | ||
@@ -79,0 +71,0 @@ const elements = toArray(ev.target.elements); |
{ | ||
"name": "@uppy/form", | ||
"description": "Connect Uppy to an existing HTML <form>.", | ||
"version": "3.2.1", | ||
"version": "3.2.2", | ||
"license": "MIT", | ||
@@ -28,4 +28,4 @@ "main": "lib/index.js", | ||
"peerDependencies": { | ||
"@uppy/core": "^3.11.0" | ||
"@uppy/core": "^3.13.1" | ||
} | ||
} |
@@ -10,5 +10,9 @@ # @uppy/form | ||
The Form plugin collects metadata from any specified `<form>` element, right before Uppy begins uploading/processing files. It optionally appends results back to the form. The appended result is a stringified version of a result returned from `uppy.upload()`. | ||
The Form plugin collects metadata from any specified `<form>` element, right | ||
before Uppy begins uploading/processing files. It optionally appends results | ||
back to the form. The appended result is a stringified version of a result | ||
returned from `uppy.upload()`. | ||
Uppy is being developed by the folks at [Transloadit](https://transloadit.com), a versatile file encoding service. | ||
Uppy is being developed by the folks at [Transloadit](https://transloadit.com), | ||
a versatile file encoding service. | ||
@@ -37,7 +41,11 @@ ## Example | ||
Alternatively, you can also use this plugin in a pre-built bundle from Transloadit’s CDN: Edgly. In that case `Uppy` will attach itself to the global `window.Uppy` object. See the [main Uppy documentation](https://uppy.io/docs/#Installation) for instructions. | ||
Alternatively, you can also use this plugin in a pre-built bundle from | ||
Transloadit’s CDN: Edgly. In that case `Uppy` will attach itself to the global | ||
`window.Uppy` object. See the | ||
[main Uppy documentation](https://uppy.io/docs/#Installation) for instructions. | ||
## Documentation | ||
Documentation for this plugin can be found on the [Uppy website](https://uppy.io/docs/form). | ||
Documentation for this plugin can be found on the | ||
[Uppy website](https://uppy.io/docs/form). | ||
@@ -44,0 +52,0 @@ ## License |
@@ -55,8 +55,2 @@ import BasePlugin, { type DefinePluginOpts } from '@uppy/core/lib/BasePlugin.js' | ||
/** | ||
* 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<M, B>, opts?: FormOptions) { | ||
@@ -75,3 +69,2 @@ super(uppy, { ...defaultOptions, ...opts }) | ||
handleUploadStart(): void { | ||
this.#completed = false | ||
if (this.opts.getMetaFromForm) { | ||
@@ -83,3 +76,2 @@ this.getMetaFromForm() | ||
handleSuccess(result: Result<M, B>): void { | ||
this.#completed = true | ||
if (this.opts.addResultToForm) { | ||
@@ -90,3 +82,8 @@ 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() | ||
} | ||
} | ||
@@ -96,3 +93,3 @@ } | ||
handleFormSubmit(ev: Event): void { | ||
if (this.opts.triggerUploadOnSubmit && !this.#completed) { | ||
if (this.opts.triggerUploadOnSubmit) { | ||
ev.preventDefault() | ||
@@ -99,0 +96,0 @@ const elements = toArray((ev.target as HTMLFormElement).elements) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53
27346
300