Expose option to limit amount of uploads in attatchment field
This commit is contained in:
parent
58cfc29dc5
commit
4788cb0a04
|
@ -18,6 +18,7 @@
|
||||||
export let fileSizeLimit = BYTES_IN_MB * 20
|
export let fileSizeLimit = BYTES_IN_MB * 20
|
||||||
export let processFiles = null
|
export let processFiles = null
|
||||||
export let handleFileTooLarge = null
|
export let handleFileTooLarge = null
|
||||||
|
export let handleTooManyFiles = null
|
||||||
export let gallery = true
|
export let gallery = true
|
||||||
export let error = null
|
export let error = null
|
||||||
export let fileTags = []
|
export let fileTags = []
|
||||||
|
@ -71,6 +72,13 @@
|
||||||
handleFileTooLarge(fileSizeLimit, value)
|
handleFileTooLarge(fileSizeLimit, value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fileCount = fileList.length + value.length
|
||||||
|
if (handleTooManyFiles && maximum && fileCount > maximum) {
|
||||||
|
handleTooManyFiles(maximum)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (processFiles) {
|
if (processFiles) {
|
||||||
const processedFiles = await processFiles(fileList)
|
const processedFiles = await processFiles(fileList)
|
||||||
const newValue = [...value, ...processedFiles]
|
const newValue = [...value, ...processedFiles]
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
export let fileSizeLimit = undefined
|
export let fileSizeLimit = undefined
|
||||||
export let processFiles = undefined
|
export let processFiles = undefined
|
||||||
export let handleFileTooLarge = undefined
|
export let handleFileTooLarge = undefined
|
||||||
|
export let handleTooManyFiles = undefined
|
||||||
export let gallery = true
|
export let gallery = true
|
||||||
export let fileTags = []
|
export let fileTags = []
|
||||||
export let maximum = undefined
|
export let maximum = undefined
|
||||||
|
@ -30,6 +31,7 @@
|
||||||
{fileSizeLimit}
|
{fileSizeLimit}
|
||||||
{processFiles}
|
{processFiles}
|
||||||
{handleFileTooLarge}
|
{handleFileTooLarge}
|
||||||
|
{handleTooManyFiles}
|
||||||
{gallery}
|
{gallery}
|
||||||
{fileTags}
|
{fileTags}
|
||||||
{maximum}
|
{maximum}
|
||||||
|
|
|
@ -2791,6 +2791,12 @@
|
||||||
"label": "Extensions",
|
"label": "Extensions",
|
||||||
"key": "extensions"
|
"key": "extensions"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "number",
|
||||||
|
"label": "No. of attachment",
|
||||||
|
"key": "maximum",
|
||||||
|
"min": 1
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "event",
|
"type": "event",
|
||||||
"label": "On Change",
|
"label": "On Change",
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
export let validation
|
export let validation
|
||||||
export let extensions
|
export let extensions
|
||||||
export let onChange
|
export let onChange
|
||||||
|
export let maximum = undefined
|
||||||
|
|
||||||
let fieldState
|
let fieldState
|
||||||
let fieldApi
|
let fieldApi
|
||||||
|
@ -25,6 +26,12 @@
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleTooManyFiles = fileLimit => {
|
||||||
|
notificationStore.actions.warning(
|
||||||
|
`Please select a maximum of ${fileLimit} files.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const processFiles = async fileList => {
|
const processFiles = async fileList => {
|
||||||
let data = new FormData()
|
let data = new FormData()
|
||||||
for (let i = 0; i < fileList.length; i++) {
|
for (let i = 0; i < fileList.length; i++) {
|
||||||
|
@ -66,6 +73,8 @@
|
||||||
on:change={handleChange}
|
on:change={handleChange}
|
||||||
{processFiles}
|
{processFiles}
|
||||||
{handleFileTooLarge}
|
{handleFileTooLarge}
|
||||||
|
{handleTooManyFiles}
|
||||||
|
{maximum}
|
||||||
{extensions}
|
{extensions}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
Loading…
Reference in New Issue