Aber wenn ich Sweetalert2 direkt von der Seite aus öffne, wird der Fokus wie erwartet auf die Schaltfläche „Abbrechen“ verschoben.
Wie kann ich dafür sorgen, dass focusCancel: true funktioniert, wenn Swal aus dem Modal heraus aktiviert wird?
Ich verwende die neueste Sweetalert2-Version (11.26.3) und Bootstrap 5.3.8.
Code: Select all
$('#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) {
}
});
});Code: Select all
[h4]TITLE[/h4]
Open
Close
Mobile version