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 =
(!maximum || (maximum && value?.length < maximum)) && !disabled
(!maximum || (maximum && (value?.length || 0) < maximum)) && !disabled
async function processFileList(fileList) {
if (

View File

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