Но когда я открываю Sweetalert2 непосредственно со страницы, фокус перемещается на кнопку «Отмена», как и ожидалось.
Как заставить focusCancel: true работать, когда Swal активирован из модального окна?
Я использую последнюю версию Sweetalert2 (11.26.3) и Bootstrap 5.3.8.
Код: Выделить всё
$('#btnTest1').on('click', function() {
$('#modalTest').modal('show');
$('#modalTest').off('shown.bs.modal').on('shown.bs.modal', function() {
$('#btnOpen').trigger('focus');
});
});
$('#btnOpen').on('click', function() {
Swal.fire({
title: 'Confirm 1?',
text: 'Testing 1 ..........',
icon: 'question',
showCancelButton: true,
confirmButtonText: 'Confirm 1',
cancelButtonText: 'Cancel 1',
focusCancel: true,
}).then((result) => {
if (result.isConfirmed) {
}
});
});
$('#btnTest2').on('click', function() {
Swal.fire({
title: 'Confirm 2?',
text: 'Testing 2 ..........',
icon: 'question',
showCancelButton: true,
confirmButtonText: 'Confirm 2',
cancelButtonText: 'Cancel 2',
focusCancel: true,
}).then((result) => {
if (result.isConfirmed) {
}
});
});Код: Выделить всё
[h4]TITLE[/h4]
Open
Close
Подробнее здесь: https://stackoverflow.com/questions/798 ... cel-button
Мобильная версия