#7124 - First Input Autofocus without property #251

Merged
jsegarra merged 5 commits from 7124_autofocus_first_input into dev 2024-03-25 07:17:04 +00:00
5 changed files with 30 additions and 3 deletions

View File

@ -29,7 +29,7 @@ module.exports = configure(function (/* ctx */) {
// app boot file (/src/boot) // app boot file (/src/boot)
// --> boot files are part of "main.js" // --> boot files are part of "main.js"
// https://v2.quasar.dev/quasar-cli/boot-files // https://v2.quasar.dev/quasar-cli/boot-files
boot: ['i18n', 'axios', 'vnDate', 'validations'], boot: ['i18n', 'axios', 'vnDate', 'validations', 'quasar'],
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#css // https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#css
css: ['app.scss'], css: ['app.scss'],

21
src/boot/qformMixin.js Normal file
View File

@ -0,0 +1,21 @@
import { getCurrentInstance } from 'vue';
const filterAvailableInput = element => element.classList.contains('q-field__native') && !element.disabled
const filterAvailableText = element => element.__vueParentComponent.type.name === 'QInput' && element.__vueParentComponent?.attrs?.class !== 'vn-input-date';
export default {
mounted: function () {
const vm = getCurrentInstance();
if (vm.type.name === 'QForm')
if (!['searchbarForm','filterPanelForm'].includes(this.$el?.id)) {
// AUTOFOCUS
const elementsArray = Array.from(this.$el.elements);
jsegarra marked this conversation as resolved
Review

No usar una variable si luego solo se usa una vez. Igual se te ha quedado de antes

No usar una variable si luego solo se usa una vez. Igual se te ha quedado de antes
Review

Si que se usaba en el evento key, pero eso pertenece a otra rama

Si que se usaba en el evento key, pero eso pertenece a otra rama
const firstInputElement = elementsArray.filter(filterAvailableInput).find(filterAvailableText);
if (firstInputElement) {
firstInputElement.focus();
jsegarra marked this conversation as resolved
Review

refactor de chatGpt para no usar -1
const firstInputElement = elementsArray.find(element => element.classList.contains('q-field__native'));

if (firstInputElement) {

refactor de chatGpt para no usar -1 const firstInputElement = elementsArray.find(element => element.classList.contains('q-field__native')); if (firstInputElement) {
}
}
},
};

6
src/boot/quasar.js Normal file
View File

@ -0,0 +1,6 @@
import { boot } from 'quasar/wrappers';
import qFormMixin from './qformMixin';
export default boot(({ app }) => {
app.mixin(qFormMixin);
});

View File

@ -164,7 +164,7 @@ function formatValue(value) {
</script> </script>
<template> <template>
<QForm @submit="search"> <QForm @submit="search" id="filterPanelForm">
<QList dense> <QList dense>
<QItem class="q-mt-xs"> <QItem class="q-mt-xs">
<QItemSection top> <QItemSection top>

View File

@ -108,7 +108,7 @@ async function search() {
</script> </script>
<template> <template>
<QForm @submit="search"> <QForm @submit="search" id="searchbarForm">
<VnInput <VnInput
id="searchbar" id="searchbar"
v-model="searchText" v-model="searchText"