mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-21 14:47:24 +01: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:
@@ -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, [
|
||||
|
||||
Reference in New Issue
Block a user