refs: #6911-saveOnEnter
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
jcasado 2024-05-22 12:07:27 +02:00
parent bdfafe9319
commit 4de9895b38
3 changed files with 44 additions and 19 deletions

View File

@ -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();
}
});
}
}
}
},
};

View File

@ -48,12 +48,12 @@ async function insert() {
size="lg"
autogrow
autofocus
@keyup.ctrl.enter.stop="insert"
@keyup.enter.stop="insert"
clearable
>
<template #append
><QBtn
:title="t('Save (ctrl + Enter)')"
<template #append>
<QBtn
:title="t('Save (Enter)')"
icon="save"
color="primary"
flat

View File

@ -155,7 +155,13 @@ const statesFilter = {
v-model.number="data.packages"
:label="t('globals.packages')"
:rules="validate('claim.packages')"
type="number"
type="textarea"
/>
<QInput
v-model.number="data.packages"
:label="t('globals.packages')"
:rules="validate('claim.packages')"
type="text"
/>
</div>
<div class="col">