|
@@ -228,7 +228,7 @@ Optionally, specify a string of text that explains something about the upload fo
|
|
|
|
|
|
### `metaFields: []`
|
|
|
|
|
|
-An array of UI field objects that will be shown when a user clicks the “edit” button on that file. Configuring this enables the “edit” button on file cards. Each object requires:
|
|
|
+An array of UI field objects, or a function that takes a [File Object](https://uppy.io/docs/uppy/#File-Objects) and returns an array of UI field objects, that will be shown when a user clicks the “edit” button on that file. Configuring this enables the “edit” button on file cards. Each object requires:
|
|
|
|
|
|
- `id`, the name of the meta field. Note: this will also be used in CSS/HTML as part of the `id` attribute, so it’s better to [avoid using characters like periods, semicolons, etc](https://stackoverflow.com/a/79022).
|
|
|
- `name`, the label shown in the interface.
|
|
@@ -252,6 +252,33 @@ It gets passed `({value, onChange}, h)` where `value` is the current value of th
|
|
|
})
|
|
|
```
|
|
|
|
|
|
+If you’d like the meta fields to be dynamically assigned depending on, for instance, the file type, pass a function:
|
|
|
+
|
|
|
+```js
|
|
|
+.use(Dashboard, {
|
|
|
+ trigger: '#pick-files',
|
|
|
+ metaFields: (file) => {
|
|
|
+ const fields = [{ id: 'name', name: 'File name' }]
|
|
|
+ if (file.type.startsWith('image/')) {
|
|
|
+ fields.push({ id: 'location', name: 'Photo Location' })
|
|
|
+ fields.push({ id: 'alt', name: 'Alt text' })
|
|
|
+ fields.push({
|
|
|
+ id: 'public',
|
|
|
+ name: 'Public',
|
|
|
+ render: ({ value, onChange }, h) => {
|
|
|
+ return h('input', {
|
|
|
+ type: 'checkbox',
|
|
|
+ onChange: (ev) => onChange(ev.target.checked ? 'on' : 'off'),
|
|
|
+ defaultChecked: value === 'on',
|
|
|
+ })
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return fields
|
|
|
+ },
|
|
|
+})
|
|
|
+```
|
|
|
+
|
|
|

|
|
|
|
|
|
Note that this metadata will only be set on a file object if it is entered by the user. If the user doesn't edit a file's metadata, it will not have default values; instead everything will be `undefined`. If you want to set a certain meta field to each file regardless of user actions, set [`meta` in the Uppy constructor options](/docs/uppy/#meta).
|