0
0
Fork 0

Compare commits

...

10 Commits

4 changed files with 85 additions and 32 deletions

View File

@ -0,0 +1,27 @@
import { getCurrentInstance } from 'vue';
export default {
mounted: function () {
const vm = getCurrentInstance();
if (vm.type.name === 'QForm') {
const that = this;
this.$el.addEventListener('keyup', function (evt) {
if (evt.key === 'Enter') {
const input = evt.target;
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();
}
});
}
},
};

54
src/boot/qFormFocus.js Normal file
View File

@ -0,0 +1,54 @@
export default {
mounted: function () {
// func
const observer = new MutationObserver((mutations, observerInstance) => {
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: false,
});
},
};
function focusFirstInput(input, observerInstance) {
input.focus();
observerInstance.disconnect();
return;
}

View File

@ -1,30 +0,0 @@
import { getCurrentInstance } from 'vue';
export default {
mounted: function () {
const vm = getCurrentInstance();
if (vm.type.name === 'QForm') {
if (!['searchbarForm', 'filterPanelForm'].includes(this.$el?.id)) {
// TODO: AUTOFOCUS IS NOT FOCUSING
const that = this;
this.$el.addEventListener('keyup', function (evt) {
if (evt.key === 'Enter') {
const input = evt.target;
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

@ -1,12 +1,14 @@
import { boot } from 'quasar/wrappers'; import { boot } from 'quasar/wrappers';
import qFormMixin from './qformMixin'; import qFormEnterEvent from './qFormEnterEvent';
import qFormFocus from './qFormFocus';
import mainShortcutMixin from './mainShortcutMixin'; import mainShortcutMixin from './mainShortcutMixin';
import keyShortcut from './keyShortcut'; import keyShortcut from './keyShortcut';
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
const { notify } = useNotify(); const { notify } = useNotify();
export default boot(({ app }) => { export default boot(({ app }) => {
app.mixin(qFormMixin); app.mixin(qFormEnterEvent);
app.mixin(qFormFocus);
app.mixin(mainShortcutMixin); app.mixin(mainShortcutMixin);
app.directive('shortcut', keyShortcut); app.directive('shortcut', keyShortcut);
app.config.errorHandler = function (err) { app.config.errorHandler = function (err) {