Cosmetics
Some checks failed
/ Run tests (push) Successful in 1m52s
/ Run system tests (push) Failing after 2m3s
/ Build, push and deploy image (push) Successful in 1m45s

This commit is contained in:
david 2024-11-11 05:00:51 +01:00
parent ee5dbcf33e
commit e569bcb246
21 changed files with 54 additions and 65 deletions

View file

@ -10,18 +10,11 @@ export default class extends Controller {
isSubmitted = false
connect() {
console.log("connect unsaved-changes")
this.initialState = this.formState()
console.log("usaved-changes connect ", this.cancelTargets)
window.addEventListener("beforeunload", (event) => this.leavingPage(event))
document.addEventListener('turbo:before-visit', (e) => this.leavingPage(e))
this.element.addEventListener("submit", (_) => this.isSubmitted = true)
// this.cancelTargets.forEach(element => {
// console.log(element)
// element.addEventListener("onclick", (_) => this.reset())
// });
}
formState() {
@ -31,17 +24,14 @@ export default class extends Controller {
}
reset() {
console.log("reset")
this.initialState = this.formState()
}
hasChanged() {
console.log("hasChanged result", this.initialState != this.formState())
return this.formState() != this.initialState
}
leavingPage(event) {
console.log(event.type)
if (this.isSubmitted || !this.hasChanged()) {
return
}