From aa89b0260a41c1aab8cdb3865da245a64836ca92 Mon Sep 17 00:00:00 2001 From: BartChris Date: Fri, 10 May 2024 10:49:14 +0200 Subject: [PATCH] Handle enter event in input fields --- .../WEB-INF/resources/js/metadata_editor.js | 27 +++++++++++++++++++ .../includes/metadataTreeTable.xhtml | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Kitodo/src/main/webapp/WEB-INF/resources/js/metadata_editor.js b/Kitodo/src/main/webapp/WEB-INF/resources/js/metadata_editor.js index 476ad6b0009..8dfd3459dc0 100644 --- a/Kitodo/src/main/webapp/WEB-INF/resources/js/metadata_editor.js +++ b/Kitodo/src/main/webapp/WEB-INF/resources/js/metadata_editor.js @@ -16,6 +16,33 @@ var metadataEditor = {}; +metadataEditor.metadataTree = { + + /** + * Key down event for all inputText elements in the metadata tree. + * If the key is "enter", handle it like a "tab"-event. + * @param event the corresponding key down event + * @param element the corresponding element + */ + handleKeyDown(event, element) { + // Check if the pressed key is 'Enter' + if (event.keyCode === 13 || event.key === "Enter") { + event.preventDefault(); + let form = element.form; + let focusableElements = Array.from(form.elements).filter((element) => { + return element.tabIndex >= 0 && !element.disabled; + }); + let index = focusableElements.indexOf(element); + let nextInput = focusableElements[index + 1]; + if (nextInput) { + // Focus on the next input element + nextInput.focus(); + } + } + }, + +}; + /** * Methods and events related to the gallery section of the meta data editor. */ diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataTreeTable.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataTreeTable.xhtml index 8d9da242d61..2e5e9052306 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataTreeTable.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataTreeTable.xhtml @@ -63,7 +63,8 @@ value="#{item.value}" disabled="#{not item.editable or readOnly}" required="#{item.required and (not empty param['editForm:save'] or not empty param['editForm:saveContinue'])}" - styleClass="#{not item.editable or readOnly ? 'read-only disabled' : ''}"> + styleClass="#{not item.editable or readOnly ? 'read-only disabled' : ''}" + onkeydown="metadataEditor.metadataTree.handleKeyDown(event, this)">