Autofocus for frequently used input fields

Fixes #1157.
- Focus `name` field on new part
- Focus `amount` on add/withdraw modal
- Focus first "number type" input on any newly added collectionType table row... (debatable)

It would be even more favorable if the user could configure if they want to use autofocus and/or for which fields/dialogs it should be enabled.
This commit is contained in:
buchmann 2026-02-11 14:10:05 +01:00
parent 41252d8bb9
commit 76f0b05a09
4 changed files with 11 additions and 0 deletions

View file

@ -79,9 +79,13 @@ export default class extends Controller {
//Afterwards return the newly created row
if(targetTable.tBodies[0]) {
targetTable.tBodies[0].insertAdjacentHTML('beforeend', newElementStr);
var fields = targetTable.tBodies[0].querySelectorAll("input[type=number]");
fields[fields.length - 1].focus();
return targetTable.tBodies[0].lastElementChild;
} else { //Otherwise just insert it
targetTable.insertAdjacentHTML('beforeend', newElementStr);
var fields = targetTable.querySelectorAll("input[type=number]");
fields[fields.length - 1].focus();
return targetTable.lastElementChild;
}
}

View file

@ -5,6 +5,7 @@ export default class extends Controller
{
connect() {
this.element.addEventListener('show.bs.modal', event => this._handleModalOpen(event));
this.element.addEventListener('shown.bs.modal', event => this._handleModalShown(event));
}
_handleModalOpen(event) {
@ -61,4 +62,8 @@ export default class extends Controller
amountInput.setAttribute('max', lotAmount);
}
}
_handleModalShown(event) {
this.element.querySelector('input[name="amount"]').focus();
}
}