Skip to content

Commit

Permalink
Ensure only one <form> is synced per instance
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Nov 17, 2024
1 parent dd1741c commit d86e6b5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class OptionsSync<UserOptions extends Options> {
The form fields' `name` attributes will have to match the option names.
*/
async syncForm(form: string | HTMLFormElement): Promise<void> {
this.stopSyncForm();
this._form = form instanceof HTMLFormElement
? form
: document.querySelector<HTMLFormElement>(form)!;
Expand All @@ -192,7 +193,7 @@ class OptionsSync<UserOptions extends Options> {
/**
Removes any listeners added by `syncForm`
*/
async stopSyncForm(): Promise<void> {
stopSyncForm(): void {
if (this._form) {
this._form.removeEventListener('input', this._handleFormInput);
this._form.removeEventListener('submit', this._handleFormSubmit);
Expand Down

0 comments on commit d86e6b5

Please # to comment.