2021-01-29 14:22:38 +01:00
|
|
|
<script>
|
2021-02-05 11:53:25 +01:00
|
|
|
import Field from "./Field.svelte"
|
2021-01-29 14:22:38 +01:00
|
|
|
import Dropzone from "../attachments/Dropzone.svelte"
|
2021-02-01 12:14:24 +01:00
|
|
|
import { onMount } from "svelte"
|
2021-01-29 14:22:38 +01:00
|
|
|
|
|
|
|
export let field
|
|
|
|
export let label
|
2021-02-17 16:16:44 +01:00
|
|
|
export let disabled = false
|
2021-01-29 14:22:38 +01:00
|
|
|
|
|
|
|
let fieldState
|
|
|
|
let fieldApi
|
2021-02-01 12:14:24 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
|
})
|
2021-01-29 14:22:38 +01:00
|
|
|
</script>
|
|
|
|
|
2021-02-05 11:53:25 +01:00
|
|
|
<Field
|
|
|
|
{label}
|
|
|
|
{field}
|
2021-02-17 16:16:44 +01:00
|
|
|
{disabled}
|
2021-02-05 11:53:25 +01:00
|
|
|
type="attachment"
|
|
|
|
bind:fieldState
|
|
|
|
bind:fieldApi
|
|
|
|
defaultValue={[]}>
|
2021-02-01 12:14:24 +01:00
|
|
|
{#if mounted}
|
2021-02-17 16:16:44 +01:00
|
|
|
<div class:disabled={$fieldState.disabled}>
|
|
|
|
<Dropzone bind:files={value} />
|
|
|
|
</div>
|
2021-01-29 14:22:38 +01:00
|
|
|
{/if}
|
2021-02-05 11:53:25 +01:00
|
|
|
</Field>
|
2021-02-17 16:16:44 +01:00
|
|
|
|
|
|
|
<style>
|
|
|
|
div.disabled :global(> *) {
|
|
|
|
background-color: var(--spectrum-global-color-gray-200) !important;
|
|
|
|
pointer-events: none !important;
|
|
|
|
}
|
|
|
|
</style>
|