From ce28757a1a712d5962aa80f90a6000253e4d032c Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 22 Nov 2024 08:54:19 +0100 Subject: [PATCH] feat: refs #8163 maxLengthVnInput --- src/components/common/VnInput.vue | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/common/VnInput.vue b/src/components/common/VnInput.vue index 881e8ef5d..1aa36bf4f 100644 --- a/src/components/common/VnInput.vue +++ b/src/components/common/VnInput.vue @@ -73,6 +73,9 @@ const mixinRules = [ requiredFieldRule, ...($attrs.rules ?? []), (val) => { + const { maxlength } = vnInputRef.value; + if (maxlength && +val.length > maxlength) + return t(`maxLength`, { value: maxlength }); const { min, max } = vnInputRef.value.$attrs; if (!min) return null; if (min >= 0) if (Math.floor(val) < min) return t('inputMin', { value: min }); @@ -83,13 +86,9 @@ const mixinRules = [ }, ]; -const insertMode = ref(false); - const handleKeydown = (e) => { - if ($props.insertable && e.key === 'Insert') { - insertMode.value = !insertMode.value; - } - if (insertMode.value && e.key !== 'Insert') { + if (e.key === 'Backspace') return; + if ($props.insertable && e.key.match(/[0-9]/)) { handleInsertMode(e); } }; @@ -99,9 +98,10 @@ const handleInsertMode = (e) => { const input = e.target; const cursorPos = input.selectionStart; + let currentValue = value.value; + if (!currentValue) currentValue = e.key; const newValue = Number(e.key); if (newValue && !isNaN(newValue)) { - const currentValue = value.value; value.value = currentValue.substring(0, cursorPos) + newValue + @@ -158,9 +158,11 @@ const handleInsertMode = (e) => { en: inputMin: Must be more than {value} + maxLength: The value exceeds {value} characters inputMax: Must be less than {value} es: inputMin: Debe ser mayor a {value} + maxLength: El valor excede los {value} carácteres inputMax: Debe ser menor a {value}