Created
August 2, 2021 15:44
-
-
Save existentialmutt/88d9c4a611afa732ce06fb85727054b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { Controller } from "stimulus"; | |
export default class extends Controller { | |
connect() { | |
this.element[this.identifier + "-controller"] = this; | |
} | |
confirm() { | |
return new Promise((resolve, reject) => { | |
this.confirmationResolve = resolve; | |
this.confirmationReject = reject; | |
$(this.element).modal({ backdrop: "static", keyboard: false }); | |
}); | |
} | |
accept(event) { | |
event.preventDefault(); | |
$(this.element).modal("hide"); | |
if (this.confirmationResolve) { | |
this.confirmationResolve(); | |
} | |
} | |
reject(event) { | |
event.preventDefault(); | |
$(this.element).modal("hide"); | |
if (this.confirmationReject) { | |
this.confirmationReject(); | |
} | |
} | |
} |
This file contains hidden or 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
// open the modal and tell it what to do after confirm | |
this.confirmationModalController.confirm().then(() => { | |
this.doWhateverNeededConfirmation() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment