forked from verdnatura/salix-front
feat: refs #8163 limit with maxLength
This commit is contained in:
parent
aae475bf4c
commit
2fa8c3f88a
|
@ -88,6 +88,7 @@ const mixinRules = [
|
||||||
|
|
||||||
const handleKeydown = (e) => {
|
const handleKeydown = (e) => {
|
||||||
if (e.key === 'Backspace') return;
|
if (e.key === 'Backspace') return;
|
||||||
|
|
||||||
if ($props.insertable && e.key.match(/[0-9]/)) {
|
if ($props.insertable && e.key.match(/[0-9]/)) {
|
||||||
handleInsertMode(e);
|
handleInsertMode(e);
|
||||||
}
|
}
|
||||||
|
@ -97,20 +98,19 @@ const handleInsertMode = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const input = e.target;
|
const input = e.target;
|
||||||
const cursorPos = input.selectionStart;
|
const cursorPos = input.selectionStart;
|
||||||
|
const { maxlength } = vnInputRef.value;
|
||||||
let currentValue = value.value;
|
let currentValue = value.value;
|
||||||
if (!currentValue) currentValue = e.key;
|
if (!currentValue) currentValue = e.key;
|
||||||
const newValue = Number(e.key);
|
const newValue = e.key;
|
||||||
if (newValue && !isNaN(newValue)) {
|
if (newValue && !isNaN(newValue) && cursorPos < maxlength) {
|
||||||
value.value =
|
value.value =
|
||||||
currentValue.substring(0, cursorPos) +
|
currentValue.substring(0, cursorPos) +
|
||||||
newValue +
|
newValue +
|
||||||
currentValue.substring(cursorPos + 1);
|
currentValue.substring(cursorPos + 1);
|
||||||
|
|
||||||
nextTick(() => {
|
|
||||||
input.setSelectionRange(cursorPos + 1, cursorPos + 1);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
nextTick(() => {
|
||||||
|
input.setSelectionRange(cursorPos + 1, cursorPos + 1);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue