Cosmetics
This commit is contained in:
parent
729ed13521
commit
6db0b64f4c
7 changed files with 27 additions and 13 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue