1
0
Fork 0
mirror of synced 2024-10-05 20:44:47 +13:00

Handle display/set single attachment in form

This commit is contained in:
Adria Navarro 2024-03-26 14:30:04 +01:00
parent f41da36995
commit b660e7e286

View file

@ -20,6 +20,11 @@
let fieldState let fieldState
let fieldApi let fieldApi
$: value =
fieldState?.value && type === FieldType.ATTACHMENT_SINGLE
? [fieldState.value]
: fieldState?.value
const { API, notificationStore } = getContext("sdk") const { API, notificationStore } = getContext("sdk")
const formContext = getContext("form") const formContext = getContext("form")
const BYTES_IN_MB = 1000000 const BYTES_IN_MB = 1000000
@ -54,6 +59,7 @@
} }
const deleteAttachments = async fileList => { const deleteAttachments = async fileList => {
console.error({ fileList })
try { try {
return await API.deleteAttachments({ return await API.deleteAttachments({
keys: fileList, keys: fileList,
@ -65,9 +71,13 @@
} }
const handleChange = e => { const handleChange = e => {
const changed = fieldApi.setValue(e.detail) let value = e.detail
if (type === FieldType.ATTACHMENT_SINGLE) {
value = value[0]
}
const changed = fieldApi.setValue(value)
if (onChange && changed) { if (onChange && changed) {
onChange({ value: e.detail }) onChange({ value })
} }
} }
</script> </script>
@ -87,7 +97,7 @@
> >
{#if fieldState} {#if fieldState}
<CoreDropzone <CoreDropzone
value={fieldState.value} {value}
disabled={fieldState.disabled || fieldState.readonly} disabled={fieldState.disabled || fieldState.readonly}
error={fieldState.error} error={fieldState.error}
on:change={handleChange} on:change={handleChange}
@ -95,7 +105,7 @@
{deleteAttachments} {deleteAttachments}
{handleFileTooLarge} {handleFileTooLarge}
{handleTooManyFiles} {handleTooManyFiles}
{maximum} maximum={type === FieldType.ATTACHMENT_SINGLE ? 1 : maximum}
{extensions} {extensions}
{compact} {compact}
/> />