Hello,
I’m trying to use Sweet Alert 2 and custom postback handlers. My javascript code:
dotvvm.postbackHandlers["postBackAlert"] = function PostBackAlert(options) {
const title = options.title;
const text = options.text;
const confirmText = options.confirmText;
const cancelText = options.cancelText;
const cssClass = options.cssClass;
return async function(next, args) {
return new Promise(function(resolve,reject) {
Swal.fire({
title: title,
text: text,
preConfirm: async function() {
Swal.showLoading();
try {
let commit = await next();
let result = await commit();
return result;
}
catch{
reject({ type: "handler", handler: this, message: "Postback aborted by error." });
}
}
})
.then((result) => {
if(result.isDismissed) {
reject({ type: "handler", handler: this, message: "Postback aborted by user." });
}
})
})
}
}
preConfirm: Function to execute before confirming, may be async (Promise-returning) or sync.
I’m trying to run the postback after the user click on the confirm button and I want to throw an error if a model error is added server side and Context.FailOnInvalidModelState().
The code is working but I’m not sure if it’s the correct way to do it. Any one has any idea and what I should fix or if it is fine to keep it like that?
Thanks