Skip to content

Commit

Permalink
#361 - Focus field on show
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Aug 12, 2024
1 parent c406b35 commit 68d26d6
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Money.Blazor.Host/wwwroot/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ window.Bootstrap = {
$select[0].setSelectionRange(0, $select[0].value.length)
}

$container.find('[data-autofocus]').first().trigger('focus');
const autofocus = $container.find('[data-autofocus]');
if (autofocus.length > 0) {
autofocus.first().trigger('focus');
}
});
}

Expand Down Expand Up @@ -123,7 +126,18 @@ window.Money = {
FocusElementById: function (id) {
const element = document.getElementById(id);
if (element) {
element.focus();
const $element = $(element);
const $modal = $element.parents(".modal");
if ($modal.length > 0 && (!$modal.data("modal") || $modal.data("modal")._isTransitioning)) {
const modal = $modal[0];
const eventHandler = e => {
element.focus();
modal.removeEventListener("shown.bs.modal", eventHandler);
}
modal.addEventListener("shown.bs.modal", eventHandler);
} else {
element.focus();
}

if ($(element).is("[data-select]")) {
element.setSelectionRange(0, element.value.length)
Expand Down

0 comments on commit 68d26d6

Please sign in to comment.