Skip to content

Commit

Permalink
Merge pull request #764 from intuitem/fix/add_library_form_change_det…
Browse files Browse the repository at this point in the history
…ection

Fix add library form change detection
  • Loading branch information
eric-intuitem authored Aug 27, 2024
2 parents db8685f + 7c76b97 commit aa08779
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/src/lib/components/Forms/FileInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let helpText: string | undefined = undefined;
export let form;
export let allowPaste: boolean = false;
export let resetSignal: boolean = false; // Reset the form value if set to true
// allowPaste should be set to false when we have multiple FileField at the same time (the ideal implementation would be to deduce to which FileInput the paste operation must be forwarded depending on the targetElement of the "paste" event)
const { errors, constraints } = formFieldProxy(form, field);
Expand Down Expand Up @@ -69,6 +70,11 @@
}
}
}
$: if (resetSignal) {
const dataTransfer = new DataTransfer();
$value = dataTransfer.files; // Empty FileList
}
</script>

<svelte:document on:paste={onPaste} />
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/routes/(app)/libraries/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import { TabGroup, Tab } from '@skeletonlabs/skeleton';
let tabSet: number = data.loadedLibrariesTable.body.length > 0 ? 0 : 1;
$: if (data.loadedLibrariesTable.body.length === 0) tabSet = 0;
let fileResetSignal = false;
</script>

<div class="card bg-white shadow">
Expand Down Expand Up @@ -69,6 +71,10 @@
onSubmit={() => {
const fileInput = document.querySelector(`input[type="file"]`);
fileInput.value = '';
fileResetSignal = true;
setTimeout(() => {
fileResetSignal = false;
}, 10);
}}
{...$$restProps}
>
Expand All @@ -77,6 +83,7 @@
helpText={m.libraryFileInYaml()}
field="file"
label={m.addYourLibrary()}
resetSignal={fileResetSignal}
/>

<button
Expand Down

0 comments on commit aa08779

Please sign in to comment.