Notify the form/buttons components of a disconnect before a page reload. This gives the native components an opportunity to reset their state before the fresh page loads.
This commit is contained in:
@@ -5,6 +5,14 @@ export default class extends BridgeComponent {
|
||||
static component = "buttons"
|
||||
static targets = [ "button" ]
|
||||
|
||||
connect() {
|
||||
window.addEventListener("beforeunload", this.handleBeforeUnload.bind(this))
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
window.removeEventListener("beforeunload", this.handleBeforeUnload.bind(this))
|
||||
}
|
||||
|
||||
buttonTargetConnected() {
|
||||
this.notifyBridgeOfConnect()
|
||||
}
|
||||
@@ -27,6 +35,14 @@ export default class extends BridgeComponent {
|
||||
})
|
||||
}
|
||||
|
||||
notifyBridgeOfDisconnect() {
|
||||
this.send("disconnect")
|
||||
}
|
||||
|
||||
handleBeforeUnload() {
|
||||
this.notifyBridgeOfDisconnect()
|
||||
}
|
||||
|
||||
#clickButton(message) {
|
||||
const selectedIndex = message.data.selectedIndex
|
||||
this.#enabledButtonTargets[selectedIndex].click()
|
||||
|
||||
Reference in New Issue
Block a user