0
0
Fork 0

perf: qFormMixin improvement

This commit is contained in:
Javier Segarra 2024-11-13 10:13:00 +01:00
parent d55764d2bc
commit 9b681d806b
2 changed files with 41 additions and 5 deletions

View File

@ -1,11 +1,48 @@
import { getCurrentInstance } from 'vue';
function focusFirstInput(input) {
input.focus();
return;
}
export default {
mounted: function () {
console.error('qformMixin mounted');
const that = this;
const form = document.querySelector('.q-form#formModel');
if (!form) return;
try {
// Login
const inputsFormCard = document.querySelectorAll(
'.q-form#formModel input:not([disabled]):not([type="checkbox"])'
);
if (inputsFormCard.length) {
// .focus();
// observerInstance.disconnect();
// return;
focusFirstInput(inputsFormCard[0]);
}
// VnNotes
const textareas = document.querySelectorAll(
'textarea:not([disabled]), [contenteditable]:not([disabled])'
);
if (textareas.length) {
// textareas[textareas.length - 1].focus();
// observerInstance.disconnect();
// return;
focusFirstInput(textareas[textareas.length - 1]);
}
// if (!inputs || inputs.length === 0) return;
const inputs = document.querySelectorAll(
'form#formModel input:not([disabled]):not([type="checkbox"])'
);
const input = inputs[0];
if (!input) return;
// if (input.type === 'textarea' || input.form) {
// AUTOFOCUS
focusFirstInput(input);
// input.focus();
// observerInstance.disconnect();
} catch (error) {
console.error(error);
}
form.addEventListener('keyup', function (evt) {
if (evt.key === 'Enter') {
const input = evt.target;
@ -23,5 +60,5 @@ export default {
that.onSubmit();
}
});
},
}, // mounted
};

View File

@ -44,7 +44,6 @@ onMounted(async () => {
<template>
<FetchData
url="Countries"
:filter="countriesFilter"
auto-load
@on-fetch="(data) => (countriesOptions = data)"
/>