Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | export default {
methods: {
handleInput(val, { inputType }) {
const timeLength = this.timepicker ? 6 : 0;
const options =
this.$options.name === 'QTimePicker'
? { separator: ':', maxLength: 8 + timeLength }
: { separator: '.', maxLength: 10 + timeLength };
if (inputType === 'deleteContentBackward' && !this.userInput) {
this.userInput = '';
return;
}
const clearVal = val.replace(/ |,|:|\./g, '');
const array = clearVal.split('');
if (
inputType === 'insertText' &&
!array[array.length - 1]?.match(/[0-9]+/)
)
return;
if (array.length > 1) array.splice(2, 0, options.separator);
if (array.length > 3 && array.length !== 4)
array.splice(5, 0, options.separator);
if (array.length > options.maxLength) return;
if (timeLength) {
if (array.length > 10) array.splice(10, 0, ', ');
if (array.length > 13) array.splice(13, 0, ':');
if (array.length > 15) array.splice(16, 0, ':');
}
if (
inputType === 'deleteContentBackward' &&
['.', ':'].includes(array[array.length - 1])
) {
array.pop();
}
const parsedInputValue = array.join('');
this.userInput = parsedInputValue;
this.$emit('input', parsedInputValue);
}
}
};
|