Cosmetics
Some checks failed
/ Run tests (push) Failing after 1m13s
/ Run system tests (push) Failing after 1m15s
/ Build, push and deploy image (push) Has been skipped

This commit is contained in:
david 2024-11-01 00:50:15 +01:00
parent 729ed13521
commit 6db0b64f4c
7 changed files with 27 additions and 13 deletions

View file

@ -11,22 +11,30 @@ export default class extends Controller {
window.addEventListener("beforeunload", (event) => this.leavingPage(event))
document.addEventListener('turbo:before-visit', (e) => this.leavingPage(e))
this.element.addEventListener("submit", (_) => this.initialState = this.formState())
}
this.element.addEventListener("submit", (_) => this.initialState = null)
}
formState() {
return JSON.stringify(Array.from(new FormData(this.element).entries())
.filter(x => x[1] != "")
.sort(x => x[0]))
.filter(x => x[1] != "")
.sort(x => x[0]))
}
leavingPage(event) {
if(this.initialState == this.formState()) {
console.log(event.type)
if (this.initialState == null || this.initialState == this.formState()) {
return
}
if (!window.confirm(LEAVE_ALERT)) {
event.preventDefault()
if (event.type == "turbo:before-visit") {
if (!window.confirm(LEAVE_ALERT)) {
event.preventDefault()
} else {
this.initialState = null
}
} else {
this.initialState = null
event.returnValue = LEAVE_ALERT;
return event.returnValue;
}
}
}