then
提取后,是否可能在preConfirm
方法中不关闭Sweetalert (2)?如果请求返回特定的内容,我想简单地保持Swal为打开状态,但是执行Swal.showValidationMessage()
而不是打开整个新警报。在then
方法中执行验证消息时,会短暂显示该消息,但警报会自动关闭。
有没有办法使警报保持打开状态?
[如果我没记错的话,您应该在Swal.showValidationMessage()
选项内而不是在preConfirm()
许诺返回中调用then()
函数。
是否可以验证您在preConfirm()
中寻找的任何输入都能正常工作?
示例:
Swal.fire({
title: "title",
text: "text",
icon: "info",
showCancelButton: true,
cancelButtonText: "Cancel",
confirmButtonText: "Done!",
html: `<input id="input1 class="swal2-input" />
<input id="input2 class="swal2-input" />`,
preConfirm: () => {
let value1 = Swal.getPopup().querySelector('#input1').value;
let value2 = Swal.getPopup().querySelector('#input2').value;
if (value1 == somethingWrong1) {
// Notify error and keep alert open.
Swal.showValidationMessage('Invalid input #1.');
} else if (value2 == somethingWrong2) {
// Notify error and keep alert open.
Swal.showValidationMessage('Invalid input #2.');
} else {
// Promise return value that will be available inside the 'then()'.
// Alert will now close.
return {
input1: input1,
input2: input2
};
}
}
}).then((inputs) => {
if (inputs !== "cancel") {
// Access the inputs using: inputs.value.input1 and inputs.value.input2
// And do whatever you want.
}
});