Skip to content

Commit c2a0294

Browse files
fix: currency formatting decimal and thousands separator (#41372)
## Description The currency input widget has formatting issues for languages that use ',' as decimal separator. Following is the explanation of the behavior & expected When the user sets the value using `defaultValue` or `setValue` for this widget. And the value is 12.33 (here . represents decimal) Then the widget shows 12.33, but it should show 12,33 (because language of the browser is set to portugese; "," is decimal) When the widget shows 12.33 (here . is not decimal) And the user focuses on the widget Then the widget shows 1233 (because, in portugese . is not decimal) When the widget is focused And it shows 1233 And the user clicks to defocus it Then the currency changes to 1.233 (because, in portugese . is not decimal) When the value of currency widget is set to 12.33 (. is decimal) Then the `<widgetName>.value` should always be 12.33 (. is decimal) BECAUSE this is actually computed value When the user inputs 12,33 (, is decimal) Then the `<widgetName>.value` should always be 12.33 (. is decimal) BECAUSE this is actually computed value <img width="866" height="306" alt="Screenshot 2025-11-11 at 7 15 22 PM" src="https://github.com/user-attachments/assets/fe9e739f-be22-42fc-8c52-e2922495239d" /> <img width="796" height="269" alt="Screenshot 2025-11-11 at 7 15 46 PM" src="https://github.com/user-attachments/assets/6ebe8e3f-fa79-4b26-937b-4f58eaebdb98" /> <img width="826" height="228" alt="Screenshot 2025-11-11 at 7 43 00 PM" src="https://github.com/user-attachments/assets/2c0c403b-55ed-4558-9b06-3ceadc22fd6c" /> <img width="848" height="262" alt="Screenshot 2025-11-12 at 3 25 26 PM" src="https://github.com/user-attachments/assets/7fc74256-8cd4-49d9-9b50-7d3b3bc865db" /> Fixes - #39583 - #21218 ## Automation /ok-to-test tags="@tag.CurrencyInput,@tag.Widget" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!IMPORTANT] > 🟣 🟣 🟣 Your tests are running. > Tests running at: <https://github.com/appsmithorg/appsmith/actions/runs/19293503615> > Commit: cab318c > Workflow: `PR Automation test suite` > Tags: `@tag.CurrencyInput,@tag.Widget` > Spec: `` > <hr>Wed, 12 Nov 2025 10:00:28 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed currency input formatting for programmatically set values. Currency inputs now properly display according to your browser's locale format (e.g., comma decimal separator in Portuguese, period in English) when initially populated. * **Chores** * Updated version control ignore patterns. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: rangrik <pranav@shoja.ai>
1 parent f092c5d commit c2a0294

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ mongo-data**
4545

4646
# ignore the task file as it will be different for different project implementations.
4747
TASKS.md
48+
mongodb*

app/client/src/widgets/CurrencyInputWidget/widget/index.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,25 @@ class CurrencyInputWidget extends BaseInputWidget<
539539
};
540540

541541
isTextFormatted = () => {
542-
return this.props.text.includes(getLocaleThousandSeparator());
542+
const text = this.props.text;
543+
const thousandSep = getLocaleThousandSeparator();
544+
545+
// Check if text contains thousand separator
546+
if (!text.includes(thousandSep)) {
547+
return false;
548+
}
549+
550+
// If text looks like an unformatted number (e.g., "12.33" where . is meant as decimal,
551+
// not thousand separator), it's not actually formatted yet.
552+
// Unformatted numbers from defaultText will only contain digits, optional minus, and at most one dot.
553+
const unformattedNumberPattern = /^-?\d+\.?\d*$/;
554+
555+
if (unformattedNumberPattern.test(text)) {
556+
return false;
557+
}
558+
559+
// Otherwise, assume it's formatted (contains thousand separators in proper context)
560+
return true;
543561
};
544562

545563
handleFocusChange = (isFocused?: boolean) => {

0 commit comments

Comments
 (0)