Поскольку я не хочу, чтобы пользователям приходилось нажимать «Сохранить», swal закрывается, и им приходится вручную открывать его снова, чтобы добавить следующую запись, я хочу добавить кнопку «Сохранить и добавить еще одну»... Как мне это сделать?
На данный момент у меня есть функция (js), где я что-то делаю, а затем показываю swal (swal.fire()...)
При нажатии "Сохранить" я делаю вызов ajax, и после успеха я просто закрываюсь.
Можно ли нажать «Сохранить и добавить еще», чтобы выполнить вызов ajax и просто вызвать ту же функцию?
Код: Выделить всё
async function addNew() {
let html = `Here is some HTML stuff to have multiple input fields`;
Swal.fire({
title: 'Add ',
html: html,
heightAuto: false,
iconHtml: icon,
showCancelButton: true,
showDenyButton: true,
confirmButtonColor: 'var(--signaturecolor)',
cancelButtonColor: 'var(--raginghamster)',
confirmButtonText: 'Save',
denyButtonText: 'Save and add another',
allowOutsideClick: false,
draggable: true
}).then((result) => {
//SAVE
if (result.isConfirmed) {
$.ajax({
type: 'Post',
url: '/Add_Charge',
async: false,
data: {
// filling arguments
},
headers: { },
success: function (data) {
swal.close();
showToast("Added");
setTimeout(function () {
location.reload()
}, 2000);
timeout += 500;
},
error: function (data) { errorSwal('blabla'); }
})
}
//SAVE AND ADD ANOTHER
if (result.isDenied) {
$.ajax({
type: 'Post',
url: '/Add_Charge',
async: false,
data: {
// filling arguments
},
headers: { },
success: function (data) {
// This one is failing, when I want to add another record
addNew();
},
error: function (data) { errorSwal('blabla'); }
})
}
if (result.dismiss) {
swal.close();
}
});
Подробнее здесь: https://stackoverflow.com/questions/798 ... mass-input
Мобильная версия