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

View file

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