0
0
Fork 0

Compare commits

...

2 Commits

3 changed files with 15 additions and 16 deletions

View File

@ -73,6 +73,9 @@ const mixinRules = [
requiredFieldRule, requiredFieldRule,
...($attrs.rules ?? []), ...($attrs.rules ?? []),
(val) => { (val) => {
const { maxlength } = vnInputRef.value;
if (maxlength && +val.length > maxlength)
return t(`maxLength`, { value: maxlength });
const { min, max } = vnInputRef.value.$attrs; const { min, max } = vnInputRef.value.$attrs;
if (!min) return null; if (!min) return null;
if (min >= 0) if (Math.floor(val) < min) return t('inputMin', { value: min }); 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) => { const handleKeydown = (e) => {
if ($props.insertable && e.key === 'Insert') { if (e.key === 'Backspace') return;
insertMode.value = !insertMode.value; if ($props.insertable && e.key.match(/[0-9]/)) {
}
if (insertMode.value && e.key !== 'Insert') {
handleInsertMode(e); handleInsertMode(e);
} }
}; };
@ -99,9 +98,10 @@ const handleInsertMode = (e) => {
const input = e.target; const input = e.target;
const cursorPos = input.selectionStart; const cursorPos = input.selectionStart;
let currentValue = value.value;
if (!currentValue) currentValue = e.key;
const newValue = Number(e.key); const newValue = Number(e.key);
if (newValue && !isNaN(newValue)) { if (newValue && !isNaN(newValue)) {
const currentValue = value.value;
value.value = value.value =
currentValue.substring(0, cursorPos) + currentValue.substring(0, cursorPos) +
newValue + newValue +
@ -158,9 +158,11 @@ const handleInsertMode = (e) => {
<i18n> <i18n>
en: en:
inputMin: Must be more than {value} inputMin: Must be more than {value}
maxLength: The value exceeds {value} characters
inputMax: Must be less than {value} inputMax: Must be less than {value}
es: es:
inputMin: Debe ser mayor a {value} inputMin: Debe ser mayor a {value}
maxLength: El valor excede los {value} carácteres
inputMax: Debe ser menor a {value} inputMax: Debe ser menor a {value}
</i18n> </i18n>
<style lang="scss"> <style lang="scss">

View File

@ -106,6 +106,7 @@ function handleLocation(data, location) {
clearable clearable
data-cy="supplierFiscalDataAccount" data-cy="supplierFiscalDataAccount"
insertable insertable
:maxlength="10"
/> />
<VnSelect <VnSelect
:label="t('supplier.fiscalData.sageTaxTypeFk')" :label="t('supplier.fiscalData.sageTaxTypeFk')"

View File

@ -2,24 +2,20 @@ describe('VnInput Component', () => {
beforeEach(() => { beforeEach(() => {
cy.login('developer'); cy.login('developer');
cy.viewport(1920, 1080); cy.viewport(1920, 1080);
cy.visit('/#/supplier/1/fiscal-data');
cy.domContentLoad();
}); });
it('should replace character at cursor position in insert mode', () => { it('should replace character at cursor position in insert mode', () => {
cy.visit('/#/supplier/1/fiscal-data');
// Simula escribir en el input // Simula escribir en el input
cy.dataCy('supplierFiscalDataAccount').find('input').clear(); cy.dataCy('supplierFiscalDataAccount').find('input').clear();
cy.dataCy('supplierFiscalDataAccount').find('input').type('0123456789'); cy.dataCy('supplierFiscalDataAccount').find('input').type('4100000001');
// Activa el modo de inserción
cy.dataCy('supplierFiscalDataAccount')
.find('input')
.trigger('keydown', { key: 'Insert' });
// Coloca el cursor en la posición 0 // Coloca el cursor en la posición 0
cy.dataCy('supplierFiscalDataAccount').find('input').type('{moveToStart}'); cy.dataCy('supplierFiscalDataAccount').find('input').type('{movetostart}');
// Escribe un número y verifica que se reemplace correctamente // Escribe un número y verifica que se reemplace correctamente
cy.dataCy('supplierFiscalDataAccount').find('input').type('999'); cy.dataCy('supplierFiscalDataAccount').find('input').type('999');
cy.dataCy('supplierFiscalDataAccount') cy.dataCy('supplierFiscalDataAccount')
.find('input') .find('input')
.should('have.value', '9993456789'); .should('have.value', '9990000001');
}); });
}); });