Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Form reset
Browse files Browse the repository at this point in the history
Takshil-Kunadia committed Oct 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 64920df commit d8d6b33
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/form/index.html
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@
</head>
<body>
<main>
<tp-form prevent-submit="yes">
<tp-form prevent-submit="yes" submit-reset="yes">
<form action="#">
<tp-form-field no-empty-spaces="yes" required="yes">
<label>Field 1</label>
14 changes: 14 additions & 0 deletions src/form/tp-form.ts
Original file line number Diff line number Diff line change
@@ -58,6 +58,20 @@ export class TPFormElement extends HTMLElement {
// If form is valid then dispatch a custom 'submit-validation-success' event.
if ( formValid ) {
this.dispatchEvent( new CustomEvent( 'submit-validation-success', { bubbles: true } ) );

// If reset form is enabled then reset the form.
if ( 'yes' === this.getAttribute( 'submit-reset' ) && this.form ) {
// Reset form validation.
this.resetValidation();

// Reset the form.
this.form.reset();

// Reset submit button if present.
if ( submit ) {
submit.removeAttribute( 'submitting' );
}
}
}
}

0 comments on commit d8d6b33

Please sign in to comment.