Skip to content

Instantly share code, notes, and snippets.

@existentialmutt
Created August 2, 2021 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save existentialmutt/88d9c4a611afa732ce06fb85727054b1 to your computer and use it in GitHub Desktop.
Save existentialmutt/88d9c4a611afa732ce06fb85727054b1 to your computer and use it in GitHub Desktop.
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();
}
}
}
// 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