forked from verdnatura/salix-front
feat: form focus
This commit is contained in:
parent
c8fbef1754
commit
81f7b8aa70
|
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
import { getCurrentInstance } from 'vue';
|
||||
|
||||
export default {
|
||||
mounted() {
|
||||
const vm = getCurrentInstance();
|
||||
if (vm.type.name === 'QForm') {
|
||||
if (!['searchbarForm', 'filterPanelForm'].includes(this.$el?.id))
|
||||
this.observeForInputs();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
observeForInputs() {
|
||||
const observer = new MutationObserver((mutations, observerInstance) => {
|
||||
const firstInput = this.$el.querySelector(
|
||||
'input:not([disabled]):not([type="checkbox"], textarea:not([disabled]), [contenteditable]:not([disabled])'
|
||||
);
|
||||
if (firstInput) {
|
||||
firstInput.focus();
|
||||
observerInstance.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(this.$el, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue