diff --git a/quasar.config.js b/quasar.config.js index 2d828950..80ddc375 100644 --- a/quasar.config.js +++ b/quasar.config.js @@ -29,7 +29,7 @@ module.exports = configure(function (/* ctx */) { // app boot file (/src/boot) // --> boot files are part of "main.js" // 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 css: ['app.scss'], diff --git a/src/boot/qformMixin.js b/src/boot/qformMixin.js new file mode 100644 index 00000000..7130b071 --- /dev/null +++ b/src/boot/qformMixin.js @@ -0,0 +1,28 @@ +import { QForm } from 'quasar'; +import { getCurrentInstance } from 'vue'; + +export default { + inject: { QForm }, + component: { QForm }, + components: { QForm }, + extends: { QForm }, + mounted: function () { + const vm = getCurrentInstance(); + if (vm.type.name === 'QForm') + if (![ 'searchbarForm'].includes(this.$el?.id)) { + let that = this; + const elementsArray = Array.from(this.$el.elements); + const index = elementsArray.findIndex(element => element.classList.contains('q-field__native')); + + if (index !== -1) { + const firstInputElement = elementsArray[index]; + firstInputElement.focus(); + } + document.addEventListener('keyup', function (evt) { + if (evt.keyCode === 13) { + that.onSubmit(); + } + }); + } + }, +}; diff --git a/src/boot/quasar.js b/src/boot/quasar.js new file mode 100644 index 00000000..a8d9b7ad --- /dev/null +++ b/src/boot/quasar.js @@ -0,0 +1,6 @@ +import { boot } from 'quasar/wrappers'; +import qFormMixin from './qformMixin'; + +export default boot(({ app }) => { + app.mixin(qFormMixin); +}); diff --git a/src/components/ui/VnSearchbar.vue b/src/components/ui/VnSearchbar.vue index baab4829..a8065948 100644 --- a/src/components/ui/VnSearchbar.vue +++ b/src/components/ui/VnSearchbar.vue @@ -108,7 +108,7 @@ async function search() {