From 6e39f6170d3124ee80005ea833329e8812f7c3a9 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Fri, 7 Jan 2022 17:16:17 -0300 Subject: [PATCH] fix rut bug when using backspace --- frontend/src/views/Agendar/AgendarComponent.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/Agendar/AgendarComponent.js b/frontend/src/views/Agendar/AgendarComponent.js index 0b570ea..48e519a 100644 --- a/frontend/src/views/Agendar/AgendarComponent.js +++ b/frontend/src/views/Agendar/AgendarComponent.js @@ -72,7 +72,7 @@ export default function AgendarComponent() { }; const handleRutChange = (event) => { - let value = event.target.value.replace(/\./g, '').replace('-', ''); + let value = Rut.limpiar(event.target.value); if (value.match(/[^0-9k]/ig)) { value = value.replace(value, ''); } @@ -88,6 +88,15 @@ export default function AgendarComponent() { else if (value.match(/^(\d)(\d{0,2})$/)) { value = value.replace(/^(\d)(\d{0,2})$/, '$1.$2'); } + + if (value.substr(value.length - 1, 1) === '-') { + value = value.substr(0, value.length - 1); + } + + if (value.substr(value.length - 1, 1) === '.') { + value = value.substr(0, value.length - 1); + } + setRut(value); }