Skip to content

Commit 20f39f5

Browse files
committed
Added clearOnCancel to form dialog
1 parent 43a2368 commit 20f39f5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

client/lib/FormDialog.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
let {
55
children,
66
dialog = $bindable(),
7-
submitText = 'Submit',
87
cancel = () => {},
8+
clearOnCancel = false,
9+
submitText = 'Submit',
910
submit = (data: object): Promise<any> => Promise.resolve(),
1011
pageMode = false,
1112
submitDanger = false,
@@ -15,10 +16,11 @@
1516
}: {
1617
children(): any;
1718
dialog?: HTMLDialogElement;
19+
clearOnCancel?: boolean;
20+
/** A callback for when the dialog is canceled */
21+
cancel?(): unknown;
1822
/** Change the text displayed for the submit button */
1923
submitText?: string;
20-
/** Basically a callback for when the dialog is canceled */
21-
cancel?(): unknown;
2224
/** Called on submission, this should do the actual submission */
2325
submit?(data: Record<string, FormDataEntryValue>): Promise<any>;
2426
/** Whether to display the dialog as a full-page form */
@@ -36,6 +38,7 @@
3638
3739
function onclose(e: Event) {
3840
e.preventDefault();
41+
if (clearOnCancel) dialog!.querySelector('form')!.reset();
3942
cancel();
4043
}
4144

0 commit comments

Comments
 (0)