-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2636 from digitalfabrik/fix/title-change-not-upda…
…ting-link Update page link before submitting page form
- Loading branch information
Showing
10 changed files
with
109 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
integreat_cms/static/src/js/forms/prevent-premature-submission.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* We sometimes want to perform a background task when an input element looses focus. | ||
* If the focus loss is due to the user clicking on a submission button however, the | ||
* corresponding form will be submitted before the background task is initiated. | ||
* This class is a convenient wrapper for preventing this. | ||
* | ||
* See here for more: https://github.com/digitalfabrik/integreat-cms/pull/2636 | ||
*/ | ||
export default class SubmissionPrevention { | ||
watchedElements: HTMLElement[] = []; | ||
mostRecentlyClicked: HTMLElement = null; | ||
|
||
preventSubmission = (e: Event) => { | ||
e.preventDefault(); | ||
this.mostRecentlyClicked = e.target as HTMLElement; | ||
}; | ||
|
||
constructor(identifier: string) { | ||
const elements = document.querySelectorAll<HTMLElement>(identifier); | ||
elements.forEach((element) => { | ||
element.addEventListener("click", this.preventSubmission); | ||
}); | ||
this.watchedElements = Array.from(elements); | ||
} | ||
|
||
release() { | ||
this.watchedElements.forEach((element) => { | ||
element.removeEventListener("click", this.preventSubmission); | ||
}); | ||
if (this.mostRecentlyClicked !== null) { | ||
this.mostRecentlyClicked.click(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters