From 4de9895b38c4fe1656ed48488ded941ece88e934 Mon Sep 17 00:00:00 2001 From: jcasado Date: Wed, 22 May 2024 12:07:27 +0200 Subject: [PATCH] refs: #6911-saveOnEnter --- src/boot/qformMixin.js | 47 +++++++++++++++++-------- src/components/ui/VnNotes.vue | 8 ++--- src/pages/Claim/Card/ClaimBasicData.vue | 8 ++++- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/boot/qformMixin.js b/src/boot/qformMixin.js index 52b99af46..03476207b 100644 --- a/src/boot/qformMixin.js +++ b/src/boot/qformMixin.js @@ -1,31 +1,50 @@ 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'; +const filterAvailableInput = (element) => { + return element.classList.contains('q-field__native') && !element.disabled; +}; +const filterAvailableText = (element) => { + return ( + 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 (vm.type.name === 'QForm') { if (!['searchbarForm', 'filterPanelForm'].includes(this.$el?.id)) { // AUTOFOCUS const elementsArray = Array.from(this.$el.elements); - const firstInputElement = elementsArray - .filter(filterAvailableInput) - .find(filterAvailableText); + const availableInputs = elementsArray.filter(filterAvailableInput); + const firstInputElement = availableInputs.find(filterAvailableText); if (firstInputElement) { firstInputElement.focus(); } const that = this; - document.addEventListener('keyup', function (evt) { - if (evt.key === 'Enter') { - that.onSubmit(); - } - }); + for (const availableInput of availableInputs) { + availableInput.addEventListener('keydown', (evt) => { + if (evt.key === 'Enter') { + const input = evt.target; + console.log('input', input); + if (input.type == 'textarea' && evt.shiftKey) { + evt.preventDefault(); + let { selectionStart, selectionEnd } = input; + input.value = + input.value.substring(0, selectionStart) + + '\n' + + input.value.substring(selectionEnd); + selectionStart = selectionEnd = selectionStart + 1; + return; + } + evt.preventDefault(); + that.onSubmit(); + } + }); + } } + } }, }; diff --git a/src/components/ui/VnNotes.vue b/src/components/ui/VnNotes.vue index b0cdd0e15..e43130cf3 100644 --- a/src/components/ui/VnNotes.vue +++ b/src/components/ui/VnNotes.vue @@ -48,12 +48,12 @@ async function insert() { size="lg" autogrow autofocus - @keyup.ctrl.enter.stop="insert" + @keyup.enter.stop="insert" clearable > -