Skip to content

Commit

Permalink
Merge pull request kitodo#6063 from BartChris/prevent_missing_input_f…
Browse files Browse the repository at this point in the history
…ields

Handle enter event in input fields
  • Loading branch information
solth authored May 8, 2024
2 parents 90ab583 + f3d0b6f commit 9e93112
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Kitodo/src/main/webapp/WEB-INF/resources/js/metadata_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)">
<p:ajax event="change"
oncomplete="preserveMetadata(); #{item.leading ? (request.requestURI.contains('metadataEditor') ? 'updateTitleMetadataWithTable();' : 'updateProcessMetadata();') : (request.requestURI.contains('metadataEditor') ? 'updateTitleMetadata();' : '')}"/>
</p:inputText>
Expand Down

0 comments on commit 9e93112

Please sign in to comment.