From 72032dd5c3928ae846043f80eb8b41e72cb6564c Mon Sep 17 00:00:00 2001 From: webbrain-one <295484252+webbrain-one@users.noreply.github.com> Date: Mon, 10 Aug 2026 11:59:21 +0300 Subject: [PATCH] Format input value on change instead of blur Apply formatting in realtime during the onchange event. Previously, the value was only formatted when the input lost focus. --- src/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index dcc2e8f..15eed0d 100644 --- a/src/index.js +++ b/src/index.js @@ -34,10 +34,18 @@ class FormatCurrency extends Component { const el = e.target; const inputValue = el.value; + const rawValue = (inputValue) ? removeAllButLast(inputValue.replace(/[^\d,.]/g, '').replace(',', '.'), '.') : ''; + const formattedValue = rawValue ? this.props.intl.formatNumber(rawValue, { + style: 'currency', + currency: this.props.currency, + }) : ''; + this.setState({ - value: (inputValue) ? removeAllButLast(inputValue.replace(/[^\d,.]/g, '').replace(',', '.'), '.') : '', - formattedValue: el.value, + value: rawValue, + formattedValue, }); + + el.value = formattedValue; } onFocus(e) {