Skip to content

Commit

Permalink
feat: preview form from the editor
Browse files Browse the repository at this point in the history
fixes #17
  • Loading branch information
danielo515 committed Sep 14, 2023
1 parent 809c13e commit 2d8e2d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DEFAULT_SETTINGS: ModalFormSettings = {
// Define functions and properties you want to make available to other plugins, or templater templates, etc
interface PublicAPI {
exampleForm(): Promise<FormResult>;
openForm(name: string): Promise<FormResult>;
openForm(formReference: string | FormDefinition): Promise<FormResult>
}
// This is the plugin entrypoint
export default class ModalFormPlugin extends Plugin {
Expand Down
5 changes: 4 additions & 1 deletion src/views/EditFormView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export class EditFormView extends ItemView {
},
onCancel: () => {
this.plugin.closeEditForm()
}
},
onPreview: (formDefinition) => {
this.plugin.api.openForm(formDefinition)
},
}
});
}
Expand Down
10 changes: 10 additions & 0 deletions src/views/FormBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
export let onChange: () => void;
export let onSubmit: (formDefinition: FormDefinition) => void;
export let onCancel: () => void;
export let onPreview: (formDefinition: FormDefinition) => void;
$: isValid = isValidFormDefinition(definition);
Expand Down Expand Up @@ -83,6 +84,10 @@
if (!isValidFormDefinition(definition)) return;
onSubmit(definition);
};
const handlePreview = () => {
if (!isValidFormDefinition(definition)) return;
onPreview(definition);
};
</script>

<div class="flex column gap2 wrapper modal-form">
Expand Down Expand Up @@ -128,6 +133,11 @@
>
<button type="submit" disabled={!isValid}>Save and close</button
>
<button
type="button"
on:click={handlePreview}
disabled={!isValid}>Preview</button
>
<button type="button" class="mod-warning" on:click={onCancel}
>Cancel</button
>
Expand Down

0 comments on commit 2d8e2d6

Please sign in to comment.