Created
November 2, 2020 16:16
-
-
Save dbtek/86bc71113dbb22d0dd8cb065a8f5a86a to your computer and use it in GitHub Desktop.
Uppy dashboard with custom form (w/ select) auto edit mode
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
const uppy = new Uppy.Core({ | |
meta: { | |
foo: 'bar' | |
} | |
}) | |
.use(Uppy.Dashboard, { | |
target: '#dashboard', | |
replaceTargetContent: true, | |
inline: true, | |
metaFields: [{ | |
id: 'foo', | |
name: 'Foo', | |
render: ({ value, onChange }, h) => { | |
return h( | |
'select', | |
{ value, onChange: e => onChange(e.target.value) }, | |
[ | |
h('option', { value: 'bar', selected: 'bar' === value }, 'Bar'), | |
h('option', { value: 'baz', selected: 'baz' === value }, 'Baz'), | |
] | |
); | |
} | |
}] | |
}) | |
.use(Uppy.XHRUpload, { endpoint: 'https://api2.transloadit.com' }) | |
// one caveat is that when multiple files are picked edit mode is only toggled for last item | |
// Uppy doesnt support limiting only file picker to single file selection | |
// if maxNumberOfFiles is set to 1 both file picker and dashboard is forced to upload 1 file | |
uppy.on('file-added', (file) => { | |
uppy.getPlugin('Dashboard').setPluginState({ | |
fileCardFor: file.id || null, | |
activeOverlayType: file.id ? 'FileCard' : null | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please see it in action on codepen.