我正在使用SweetAlert2(https://sweetalert2.github.io/)在执行操作之前验证用户的密码。我的承诺很有效,验证服务器中的密码并返回true或false。 密码正确时,会显示警告,确认密码验证成功。 但是,当密码不正确时,sweetalert会停止并关闭而不执行操作。不执行操作是预期的行为,但我希望它保持显示消息以提醒用户输入的密码不正确。 swal.showValidationError似乎工作正常但警报不会保持活动状态以便用户重新输入密码。
任何人都可以看看下面的代码并指出我正确的方向吗?提前谢谢
$scope.confirmPublish = function(newsFormEdit, publish, trigger, updateReason){
// Request password confirmation before Publishing a News.
// After password is successfully confirmed the event is triggered
swal({
title: $translate.instant("news_confirmPublish_title"),
text: $translate.instant("news_confirmPublish_text"),
type: 'warning',
showCancelButton: true,
confirmButtonText: $translate.instant("confirmPublish_confirmBtn"),
cancelButtonText: $translate.instant("confirmPublish_cancelBtn"),
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
buttonsStyling: true
}).then(function () {
swal({
title: 'Enter password to run ajax request',
input: 'password',
showCancelButton: true,
confirmButtonText: 'Submit',
showLoaderOnConfirm: true,
preConfirm: (pass) => {
return promisedPost('./service/verify_password.php', { pass })
.then(results => {
results = JSON.parse(results);
if (results.value === false) {
swal.showValidationError('Incorrect Password.');
} else {
return results;
}
});
},
allowOutsideClick: () => !swal.isLoading()
})
.then((result) => {
if (result.value) {
if (trigger === "create") {
$scope.createNews(newsFormEdit, publish);
} else {
$scope.updateNews(newsFormEdit, publish, updateReason);
}
swal({
type: 'success',
title: 'Ajax request finished!'
});
}
})
}, function (dismiss) {
if (dismiss === 'cancel') {
swal(
'Cancelled',
'Publish of news has been cancelled!',
'error'
)
}
})};