Docs
- Getting Started
- SME Uploader
- Companion
- List of Plugins
- Common Plugin Options
- Custom Stores
- Locale Packs
UI Elements
Sources
- Drag & Drop
- File Input
- Webcam
- Provider Plugins
- ⓒ Dropbox
- ⓒ Google Drive
- ⓒ OneDrive
- ⓒ Zoom
- ⓒ Import From URL
Destinations
File Processing
- Image Editor
- Robodog Introduction
- Robodog File Picker
- Robodog Form
- Robodog Upload
- Robodog Dashboard
- Transloadit
Miscellaneous
Contributing
Form
The @sme-uploader/form
plugin has several features to integrate with HTML <form>
elements.
- It collects user-specified metadata from form fields, right before SME Uploader begins uploading/processing files.
- It can append upload results back to the form as a hidden field. Currently the appended result is a stringified version of a
result
returned fromuploader.upload()
orcomplete
event.
const Form = require('@sme-uploader/form'); uploader.use(Form, { // Options }); |
Installation
This plugin is published as the @sme-uploader/form
package.
Install from NPM:
npm install @sme-uploader/form |
In the CDN package, it is available on the SmeUploader
global object:
const Form = SmeUploader.Form; |
Options
The @sme-uploader/form
plugin has the following configurable options:
uploader.use(Form, { target: null, resultName: 'uploaderResult', getMetaFromForm: true, addResultToForm: true, multipleResults: false, submitOnSuccess: false, triggerUploadOnSubmit: false }); |
id: 'Form'
A unique identifier for this plugin. It defaults to 'Form'
.
target: null
DOM element or CSS selector for the form element. This is required for the plugin to work.
resultName: 'uploaderResult'
The name
attribute for the <input type="hidden">
where the result will be added.
getMetaFromForm: true
Configures whether or not to extract metadata from the form. When set to true, the Form
plugin will extract all fields from a <form>
element before upload begins. Those fields will then be added to global uploader.state.meta
and each file’s meta, and appended as (meta)data to the upload in an object with [file input name attribute]
-> [file input value]
key/values.
addResultToForm: true
Configures whether or not to add upload/encoding results back to the form in an <input name="uploaderResult" 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 SME Uploader, 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:
- use
submitOnSuccess: true
if you need the form to actually be submitted once all files have been uploaded. - listen for
uploader.on('complete')
to do something else if the file uploads are all you need. For example, if the form is used for file metadata only.
submitOnSuccess: false
Configures whether or not to submit the form after SME Uploader finishes uploading/encoding.