Handle deletions

This commit is contained in:
Adria Navarro 2024-03-26 14:53:41 +01:00
parent b660e7e286
commit d74af11230
2 changed files with 9 additions and 6 deletions

View File

@ -67,7 +67,7 @@
} }
$: showDropzone = $: showDropzone =
(!maximum || (maximum && value?.length < maximum)) && !disabled (!maximum || (maximum && (value?.length || 0) < maximum)) && !disabled
async function processFileList(fileList) { async function processFileList(fileList) {
if ( if (

View File

@ -20,9 +20,12 @@
let fieldState let fieldState
let fieldApi let fieldApi
$: isSingle = schema?.type === FieldType.ATTACHMENT_SINGLE
$: value = $: value =
fieldState?.value && type === FieldType.ATTACHMENT_SINGLE isSingle && !Array.isArray(fieldState?.value)
? fieldState?.value
? [fieldState.value] ? [fieldState.value]
: []
: fieldState?.value : fieldState?.value
const { API, notificationStore } = getContext("sdk") const { API, notificationStore } = getContext("sdk")
@ -72,8 +75,8 @@
const handleChange = e => { const handleChange = e => {
let value = e.detail let value = e.detail
if (type === FieldType.ATTACHMENT_SINGLE) { if (isSingle) {
value = value[0] value = value[0] || null
} }
const changed = fieldApi.setValue(value) const changed = fieldApi.setValue(value)
if (onChange && changed) { if (onChange && changed) {
@ -105,7 +108,7 @@
{deleteAttachments} {deleteAttachments}
{handleFileTooLarge} {handleFileTooLarge}
{handleTooManyFiles} {handleTooManyFiles}
maximum={type === FieldType.ATTACHMENT_SINGLE ? 1 : maximum} maximum={isSingle ? 1 : maximum}
{extensions} {extensions}
{compact} {compact}
/> />