Skip to content

Commit faf4c56

Browse files
committed
Cleanup the hidden submit input we create
Fixes #117
1 parent d92ac1d commit faf4c56

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,12 +804,13 @@ export class ValidationService {
804804
// Because the submitter is not propagated when calling
805805
// form.submit(), we recreate it here.
806806
const submitter = submitEvent.submitter;
807+
let submitterInput: HTMLInputElement | null = null;
807808
const initialFormAction = form.action;
808809
if (submitter) {
809810
const name = submitter.getAttribute('name');
810811
// If name is null, a submit button is not submitted.
811812
if (name) {
812-
const submitterInput = document.createElement('input');
813+
submitterInput = document.createElement('input');
813814
submitterInput.type = 'hidden';
814815
submitterInput.name = name;
815816
submitterInput.value = submitter.getAttribute('value');
@@ -825,6 +826,10 @@ export class ValidationService {
825826
try {
826827
form.submit();
827828
} finally {
829+
if (submitterInput) {
830+
// Important to clean up the submit input we created.
831+
form.removeChild(submitterInput);
832+
}
828833
form.action = initialFormAction;
829834
}
830835
}

0 commit comments

Comments
 (0)