Просто добавьте блок preConfirm function на каждом шаге, который вы хотите проверить, и выполните проверку, используя переменную value , как вы хотите.Вызовите метод resol () для успеха или reject («текстовое описание ошибки здесь») , чтобы отобразить сообщение об ошибке и не дать модальной цепочке перейти к следующему шагу.
Вот пример использования вашего кода для того, чтобы сделать все поля ввода обязательными:
JSfiddle здесь: https://jsfiddle.net/davidtoledo/ymb38u6t/1
<code> swal.setDefaults({
input: 'text',
confirmButtonText: 'Next →',
showCancelButton: true,
animation: true,
progressSteps: ['1', '2', '3']
});
var steps = [
{
title: 'Customer Name',
inputId: "customer_name",
inputPlaceholder: "Write something",
preConfirm: function(value)
{
return new Promise(function(resolve, reject)
{
if (value) {
resolve();
} else {
reject('Please type something in the step 1!');
}
});
}
},
{
title: 'Sales Person',
text: 'Product sold by?',
preConfirm: function(value)
{
return new Promise(function(resolve, reject)
{
if (value) {
resolve();
} else {
reject('Please type something in the step 2!');
}
});
}
},
{
title: 'Additional Details',
text: 'Coments or additional notes',
preConfirm: function(value)
{
return new Promise(function(resolve, reject)
{
if (value) {
resolve();
} else {
reject('Please type something in the step 3!');
}
});
}
},
];
swal.queue(steps).then(function (result) {
swal.resetDefaults();
swal({
title: 'All done!',
html:
'Your answers: <pre>' +
(result) +
'
', verifyButtonText:' Lovely! ', ShowCancelButton: false})}, function () {swal.resetDefaults ()});
Приветствия,
Дэвид Коста