Autofocus confirm modal submit button

So that it can be confirmed with enter
This commit is contained in:
weeman 2024-01-29 10:54:54 +01:00 committed by Igor Scheller
parent c03ccf94c7
commit 496d75b9ef
1 changed files with 13 additions and 2 deletions

View File

@ -318,6 +318,7 @@ ready(() => {
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="${element.className}" <button type="button" class="${element.className}"
autofocus
title="${element.title}" data-submit=""> title="${element.title}" data-submit="">
${element.dataset.confirm_button_text ?? element.innerHTML} ${element.dataset.confirm_button_text ?? element.innerHTML}
</button> </button>
@ -328,15 +329,25 @@ ready(() => {
` `
); );
let modal = document.getElementById('confirmation-modal'); const modal = document.getElementById('confirmation-modal');
modal.addEventListener('hide.bs.modal', () => { modal.addEventListener('hide.bs.modal', () => {
modalOpen = false; modalOpen = false;
}); });
modal.querySelector('[data-submit]').addEventListener('click', (event) => {
const modalSubmitButton = modal.querySelector('[data-submit]');
modalSubmitButton.addEventListener('click', () => {
element.type = oldType; element.type = oldType;
element.click(); element.click();
}); });
/**
* After the modal has been shown, focus on the "Submit" button in the modal
* so that it can be confirmed with "Enter".
*/
modal.addEventListener('shown.bs.modal', () => {
modalSubmitButton.focus();
});
modalOpen = true; modalOpen = true;
let bootstrapModal = new bootstrap.Modal(modal); let bootstrapModal = new bootstrap.Modal(modal);
bootstrapModal.show(); bootstrapModal.show();