소스 검색

robodog: allow customizing `triggerUploadOnSubmit` (#1691)

* robodog: allow customizing `triggerUploadOnSubmit`

* robodog: explain when to use triggerUploadOnSubmit: false
Renée Kooi 5 년 전
부모
커밋
94efbd3ad9
2개의 변경된 파일24개의 추가작업 그리고 7개의 파일을 삭제
  1. 8 3
      packages/@uppy/robodog/src/form.js
  2. 16 4
      website/src/docs/robodog-form.md

+ 8 - 3
packages/@uppy/robodog/src/form.js

@@ -42,12 +42,17 @@ function form (target, opts) {
     submitOnSuccess = !!opts.submitOnSuccess
   }
 
-  uppy.use(Form, {
+  const formOptions = {
     target,
     triggerUploadOnSubmit: true,
-    submitOnSuccess: submitOnSuccess,
+    submitOnSuccess,
     addResultToForm: false // using custom implementation instead
-  })
+  }
+  if (opts.hasOwnProperty('triggerUploadOnSubmit')) {
+    formOptions.triggerUploadOnSubmit = opts.triggerUploadOnSubmit
+  }
+
+  uppy.use(Form, formOptions)
 
   const useDashboard = opts.dashboard || opts.modal
 

+ 16 - 4
website/src/docs/robodog-form.md

@@ -91,11 +91,23 @@ window.Robodog.form('form#my-form', {
 
 The progress bar will be inserted _into_ that element (thus _not_ replace it).
 
-<!--
-## Dashboard
+## Separating Uploads from Form Submission
 
-**TODO have an option to replace the inputs with a Dashboard modal button?**
--->
+By default, `Robodog.form` starts uploads when the user submits the form. There can be a use case for _not_ doing this, and instead uploading files in response to some user action, _before_ the form is submitted. For example, when using a Dashboard modal, the user can upload their files first and then return to the form to submit it. When they submit the form, it should not start uploading again.
+
+The `triggerUploadOnSubmit: false` option is available for this purpose. We recommend using it together with the `modal: true` and `closeAfterFinish: true` options:
+
+```js
+// Replace file input in #my-form with a button that opens the modal;
+// after the user clicks the "Upload" button inside the modal and all
+// files have been successfully uploaded, the modal closes and the user
+// can submit the form.
+window.Robodog.form('form#my-form', {
+  modal: true,
+  closeAfterFinish: true,
+  triggerUploadOnSubmit: false
+})
+```
 
 ## Migrating From the jQuery SDK