Skip to content

Commit

Permalink
feat: Export form as JSON button (danielo515#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
theotheo committed Oct 21, 2023
1 parent abe31fe commit ca20241
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/views/FormBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
validateFields,
} from "src/core/formDefinition";
import { FolderSuggest } from "src/suggesters/suggestFolder";
import { setIcon, Setting, App } from "obsidian";
import { setIcon, Setting, App, Notice } from "obsidian";
import FormRow from "./components/FormRow.svelte";
import InputBuilderDataview from "./components/inputBuilderDataview.svelte";
import InputBuilderSelect from "./components/InputBuilderSelect.svelte";
Expand Down Expand Up @@ -90,6 +90,11 @@
if (!isValidFormDefinition(definition)) return;
onPreview(definition);
};
const handleExport = () => {
if (!isValidFormDefinition(definition)) return;
navigator.clipboard.writeText(JSON.stringify(definition));
new Notice("Form has been copied to the clipboard");
};
</script>

<div class="flex column gap2 wrapper modal-form">
Expand Down Expand Up @@ -144,6 +149,11 @@
<button type="button" class="mod-warning" on:click={onCancel}
>Cancel</button
>
<button
type="button"
use:setIcon={"clipboard-copy"}
on:click={handleExport}
disabled={!isValid}/>
</div>
{#if errors.length > 0}
<h3 style="margin: 0;">
Expand Down

0 comments on commit ca20241

Please sign in to comment.