52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
function focusFirstInput(input) {
|
|
input.focus();
|
|
}
|
|
export default {
|
|
mounted: function () {
|
|
const that = this;
|
|
|
|
const form = document.querySelector('.q-form#formModel');
|
|
if (!form) return;
|
|
try {
|
|
const inputsFormCard = form.querySelectorAll(
|
|
`input:not([disabled]):not([type="checkbox"])`
|
|
);
|
|
if (inputsFormCard.length) {
|
|
focusFirstInput(inputsFormCard[0]);
|
|
}
|
|
const textareas = document.querySelectorAll(
|
|
'textarea:not([disabled]), [contenteditable]:not([disabled])'
|
|
);
|
|
if (textareas.length) {
|
|
focusFirstInput(textareas[textareas.length - 1]);
|
|
}
|
|
const inputs = document.querySelectorAll(
|
|
'form#formModel input:not([disabled]):not([type="checkbox"])'
|
|
);
|
|
const input = inputs[0];
|
|
if (!input) return;
|
|
|
|
focusFirstInput(input);
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
form.addEventListener('keyup', function (evt) {
|
|
if (evt.key === 'Enter' && !that.$attrs['prevent-submit']) {
|
|
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();
|
|
}
|
|
});
|
|
},
|
|
};
|