flows/shell: check for elements with autofocus attribute and call .focus();

closes #76
This commit is contained in:
Jens Langhammer 2020-06-18 19:09:12 +02:00
parent 3713d111a4
commit afc8baff5f
1 changed files with 7 additions and 0 deletions

View File

@ -120,6 +120,7 @@ const updateCard = (data) => {
break; break;
case "template": case "template":
flowBody.innerHTML = data.body; flowBody.innerHTML = data.body;
checkAutofocus();
updateMessages(); updateMessages();
loadFormCode(); loadFormCode();
setFormSubmitHandlers(); setFormSubmitHandlers();
@ -138,6 +139,12 @@ const loadFormCode = () => {
document.head.appendChild(newScript); document.head.appendChild(newScript);
}); });
}; };
const checkAutofocus = () => {
const autofocusElement = document.querySelector("#flow-body [autofocus]");
if (autofocusElement !== null) {
autofocusElement.focus();
}
};
const updateFormAction = (form) => { const updateFormAction = (form) => {
for (let index = 0; index < form.elements.length; index++) { for (let index = 0; index < form.elements.length; index++) {
const element = form.elements[index]; const element = form.elements[index];