From c251b87272b85ef95348196ed9b7ef54b571191d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 25 Sep 2024 14:00:25 +0200 Subject: [PATCH] feat: refs #7790 updates --- src/boot/qFormFocus.js | 52 +++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/src/boot/qFormFocus.js b/src/boot/qFormFocus.js index 466943db5..0642e67a2 100644 --- a/src/boot/qFormFocus.js +++ b/src/boot/qFormFocus.js @@ -1,18 +1,54 @@ export default { - mounted() { + mounted: function () { + // func const observer = new MutationObserver((mutations, observerInstance) => { - const firstInput = this?.$el?.querySelector( - 'input:not([disabled]):not([type="checkbox"]), textarea:not([disabled]), [contenteditable]:not([disabled])' - ); - if (firstInput?.form) { - firstInput.focus(); - observerInstance.disconnect(); + try { + // Login + const inputsFormCard = document.querySelectorAll( + 'form.formCard input:not([disabled]):not([type="checkbox"])' + ); + if (inputsFormCard.length) { + // .focus(); + // observerInstance.disconnect(); + // return; + focusFirstInput(inputsFormCard[0], observerInstance); + } + // 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], observerInstance); + } + // 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, observerInstance); + // input.focus(); + // observerInstance.disconnect(); + } catch (error) { + console.error(error); } }); observer.observe(this.$el, { childList: true, - subtree: true, + subtree: false, }); }, }; + +function focusFirstInput(input, observerInstance) { + input.focus(); + observerInstance.disconnect(); + return; +}