forked from tsai/budibase
5 changed files with 53 additions and 48 deletions
@ -1,27 +1,28 @@ |
|||||
<script> |
<script> |
||||
import SpectrumField from "./SpectrumField.svelte" |
import SpectrumField from "./SpectrumField.svelte" |
||||
import Dropzone from "../attachments/Dropzone.svelte" |
import Dropzone from "../attachments/Dropzone.svelte" |
||||
|
import { onMount } from "svelte" |
||||
|
|
||||
export let field |
export let field |
||||
export let label |
export let label |
||||
|
|
||||
let previousFiles = [] |
|
||||
let files = [] |
|
||||
$: { |
|
||||
// Only actually update the value when it changes, so that we don't trigger |
|
||||
// validation unnecessarily |
|
||||
if (files !== previousFiles) { |
|
||||
fieldApi?.setValue(files) |
|
||||
previousFiles = files |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
let fieldState |
let fieldState |
||||
let fieldApi |
let fieldApi |
||||
|
|
||||
|
// Update form value from bound value after we've mounted |
||||
|
let value |
||||
|
let mounted = false |
||||
|
$: mounted && fieldApi?.setValue(value) |
||||
|
|
||||
|
// Get the fields initial value after initialising |
||||
|
onMount(() => { |
||||
|
value = $fieldState?.value |
||||
|
mounted = true |
||||
|
}) |
||||
</script> |
</script> |
||||
|
|
||||
<SpectrumField {label} {field} bind:fieldState bind:fieldApi> |
<SpectrumField {label} {field} bind:fieldState bind:fieldApi defaultValue={[]}> |
||||
{#if fieldState} |
{#if mounted} |
||||
<Dropzone bind:files /> |
<Dropzone bind:files={value} /> |
||||
{/if} |
{/if} |
||||
</SpectrumField> |
</SpectrumField> |
||||
|
|||||
Loading…
Reference in new issue