Procházet zdrojové kódy

deprecate multipleResults option (#2996)

Artur Paikin před 3 roky
rodič
revize
f455ea59e8

+ 14 - 29
packages/@uppy/form/src/index.js

@@ -23,7 +23,6 @@ module.exports = class Form extends BasePlugin {
       resultName: 'uppyResult',
       getMetaFromForm: true,
       addResultToForm: true,
-      multipleResults: false,
       submitOnSuccess: false,
       triggerUploadOnSubmit: false,
     }
@@ -87,42 +86,28 @@ module.exports = class Form extends BasePlugin {
 
     let resultInput = this.form.querySelector(`[name="${this.opts.resultName}"]`)
     if (resultInput) {
-      if (this.opts.multipleResults) {
-        // Append new result to the previous result array.
-        // If the previous result is empty, or not an array,
-        // set it to an empty array.
-        let updatedResult
-        try {
-          updatedResult = JSON.parse(resultInput.value)
-        } catch (err) {
-          // Nothing, since we check for array below anyway
-        }
+      // Append new result to the previous result array.
+      // If the previous result is empty, or not an array,
+      // set it to an empty array.
+      let updatedResult
+      try {
+        updatedResult = JSON.parse(resultInput.value)
+      } catch (err) {
+        // Nothing, since we check for array below anyway
+      }
 
-        if (!Array.isArray(updatedResult)) {
-          updatedResult = []
-        }
-        updatedResult.push(result)
-        resultInput.value = JSON.stringify(updatedResult)
-      } else {
-        // Replace existing result with the newer result on `complete` event.
-        // This behavior is not ideal, since you most likely want to always keep
-        // all results in the input. This is kept for backwards compatability until 2.0.
-        resultInput.value = JSON.stringify(result)
+      if (!Array.isArray(updatedResult)) {
+        updatedResult = []
       }
+      updatedResult.push(result)
+      resultInput.value = JSON.stringify(updatedResult)
       return
     }
 
     resultInput = document.createElement('input')
     resultInput.name = this.opts.resultName
     resultInput.type = 'hidden'
-
-    if (this.opts.multipleResults) {
-      // Wrap result in an array so we can have multiple results
-      resultInput.value = JSON.stringify([result])
-    } else {
-      // Result is an object, kept for backwards compatability until 2.0
-      resultInput.value = JSON.stringify(result)
-    }
+    resultInput.value = JSON.stringify([result])
 
     this.form.appendChild(resultInput)
   }

+ 0 - 1
packages/@uppy/form/types/index.d.ts

@@ -7,7 +7,6 @@ declare module Form {
     resultName?: string
     getMetaFromForm?: boolean
     addResultToForm?: boolean
-    multipleResults?: boolean
     submitOnSuccess?: boolean
     triggerUploadOnSubmit?: boolean
   }

+ 0 - 7
website/src/docs/form.md

@@ -47,7 +47,6 @@ uppy.use(Form, {
   resultName: 'uppyResult',
   getMetaFromForm: true,
   addResultToForm: true,
-  multipleResults: false,
   submitOnSuccess: false,
   triggerUploadOnSubmit: false,
 })
@@ -73,12 +72,6 @@ Configures whether or not to extract metadata from the form. When set to true, t
 
 Configures whether or not to add upload/encoding results back to the form in an `<input name="uppyResult" type="hidden">` element.
 
-### `multipleResults: false`
-
-By default, the Form plugin will _replace_ the `value` of `<input type="hidden">` it adds with the result (if `addResultToForm` is enabled) on each upload / `complete` event. This behavior can be confusing, because if a user uploads a file and then adds another, only the last result will end up in the hidden input and submitted to your server.
-
-Setting `multipleResults: true` turns the value of `<input type="hidden">` into an array and _appends_ each result from `complete` event to it. Since this is likely the desired default behavior in most cases, it will be made default in the next major release of Uppy, the option is kept for backwards compatability.
-
 ### `triggerUploadOnSubmit: false`
 
 Configures whether or not to start the upload when the form is submitted. When the user presses a submit button, this will prevent form submission, and instead upload files. You can then: