forked from verdnatura/salix-front
perf: qFormMixin improvement
This commit is contained in:
parent
d55764d2bc
commit
9b681d806b
|
@ -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
|
||||
};
|
||||
|
|
|
@ -44,7 +44,6 @@ onMounted(async () => {
|
|||
<template>
|
||||
<FetchData
|
||||
url="Countries"
|
||||
:filter="countriesFilter"
|
||||
auto-load
|
||||
@on-fetch="(data) => (countriesOptions = data)"
|
||||
/>
|
||||
|
|
Loading…
Reference in New Issue