mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-02-16 14:39:37 +00:00
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:
parent
41252d8bb9
commit
76f0b05a09
4 changed files with 11 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -71,6 +71,7 @@ class BaseEntityAdminForm extends AbstractType
|
|||
'label' => 'name.label',
|
||||
'attr' => [
|
||||
'placeholder' => 'part.name.placeholder',
|
||||
'autofocus' => true,
|
||||
],
|
||||
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ class PartBaseType extends AbstractType
|
|||
'label' => 'part.edit.name',
|
||||
'attr' => [
|
||||
'placeholder' => 'part.edit.name.placeholder',
|
||||
'autofocus' => true,
|
||||
],
|
||||
])
|
||||
->add('description', RichTextEditorType::class, [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue