Skip to content

fix: preserve fixed decimals in currency input setValue#41740

Open
atharvasingh7007 wants to merge 1 commit intoappsmithorg:releasefrom
atharvasingh7007:fix/currency-input-preserve-formatted-value
Open

fix: preserve fixed decimals in currency input setValue#41740
atharvasingh7007 wants to merge 1 commit intoappsmithorg:releasefrom
atharvasingh7007:fix/currency-input-preserve-formatted-value

Conversation

@atharvasingh7007
Copy link
Copy Markdown

@atharvasingh7007 atharvasingh7007 commented Apr 15, 2026

Summary

  • preserve entered decimal precision for valid string defaults in both classic and WDS currency inputs
  • keep setValue(CurrencyInput1.value.toFixed(2)) from collapsing values like 123.00 to 123
  • add regression coverage for the currency input default-value validators

Closes #41118.

Testing

  • corepack yarn jest src/widgets/CurrencyInputWidget/widget/index.test.tsx src/widgets/wds/WDSCurrencyInputWidget/widget/index.test.tsx --runInBand
  • corepack yarn exec eslint src/widgets/CurrencyInputWidget/widget/index.tsx src/widgets/CurrencyInputWidget/widget/index.test.tsx src/widgets/wds/WDSCurrencyInputWidget/config/propertyPaneConfig/validations/defaultValueValidation.ts src/widgets/wds/WDSCurrencyInputWidget/widget/index.test.tsx
  • NODE_OPTIONS=--max-old-space-size=8192 corepack yarn check-types

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Currency input widgets now preserve decimal formatting in default values (e.g., "123.00" maintains trailing zeros instead of being normalized to "123").
  • Tests

    • Added test coverage for decimal validation scenarios with fixed decimal places.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

Walkthrough

This change adds a helper function getParsedString to two currency input widget implementations that preserves decimal precision when converting parsed numbers to strings. When the input is a string with decimal places, getParsedString uses toFixed() to maintain the original fractional digit count. Corresponding test cases validate the behavior.

Changes

Cohort / File(s) Summary
CurrencyInputWidget Implementation
app/client/src/widgets/CurrencyInputWidget/widget/index.tsx, app/client/src/widgets/CurrencyInputWidget/widget/index.test.tsx
Added getParsedString helper that checks for decimal separator in string input and preserves fractional digit count using toFixed(). Updated default-value parsing to use the helper. Test case added for valid decimal string defaults.
WDSCurrencyInputWidget Implementation
app/client/src/widgets/wds/WDSCurrencyInputWidget/config/propertyPaneConfig/validations/defaultValueValidation.ts, app/client/src/widgets/wds/WDSCurrencyInputWidget/widget/index.test.tsx
Identical getParsedString helper logic added to match CurrencyInputWidget. Default-value parsing updated to use helper. Test case added for fixed decimal place validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

💰 Trailing zeros no longer lost,
Beneath one thousand's formatted cost—
getParsedString keeps the sight,
Decimal places, sharp and bright! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the primary change: preserving fixed decimal precision in currency input when using setValue with toFixed formatting.
Description check ✅ Passed Description includes summary, testing commands, and issue reference, though it lacks the formal template structure with explicit sections and DevRel checkbox.
Linked Issues check ✅ Passed Changes implement the core requirement from #41118: preventing values like 123.00 from collapsing to 123 by preserving decimal precision in default-value validators.
Out of Scope Changes check ✅ Passed All changes are scoped to currency input validators and tests; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
app/client/src/widgets/wds/WDSCurrencyInputWidget/config/propertyPaneConfig/validations/defaultValueValidation.ts (1)

36-50: Consider extracting getParsedString to a shared utility.

This helper is duplicated in app/client/src/widgets/CurrencyInputWidget/widget/index.tsx (lines 80-94). The utilities.ts files in both widget directories already contain related decimal-handling functions like limitDecimalValue. Moving this helper there would reduce duplication.

Not blocking for this bug fix—can be addressed in a follow-up.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@app/client/src/widgets/wds/WDSCurrencyInputWidget/config/propertyPaneConfig/validations/defaultValueValidation.ts`
around lines 36 - 50, getParsedString is duplicated and should be extracted to a
shared utility: move the getParsedString implementation (which depends on
defaultDecimalSeperator and converts a numeric parsedValue to a string
preserving fractional length) into an existing shared utility module alongside
functions like limitDecimalValue, export it, and replace the local definitions
in both getParsedString usages (in defaultValueValidation.ts and
CurrencyInputWidget widget/index.tsx) with imports from that utility to remove
duplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@app/client/src/widgets/wds/WDSCurrencyInputWidget/config/propertyPaneConfig/validations/defaultValueValidation.ts`:
- Around line 36-50: getParsedString is duplicated and should be extracted to a
shared utility: move the getParsedString implementation (which depends on
defaultDecimalSeperator and converts a numeric parsedValue to a string
preserving fractional length) into an existing shared utility module alongside
functions like limitDecimalValue, export it, and replace the local definitions
in both getParsedString usages (in defaultValueValidation.ts and
CurrencyInputWidget widget/index.tsx) with imports from that utility to remove
duplication.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ca3b8fb5-7da2-4c9f-a5a6-cb78d9dc1a89

📥 Commits

Reviewing files that changed from the base of the PR and between 7d8a5ef and 9fb2c77.

📒 Files selected for processing (4)
  • app/client/src/widgets/CurrencyInputWidget/widget/index.test.tsx
  • app/client/src/widgets/CurrencyInputWidget/widget/index.tsx
  • app/client/src/widgets/wds/WDSCurrencyInputWidget/config/propertyPaneConfig/validations/defaultValueValidation.ts
  • app/client/src/widgets/wds/WDSCurrencyInputWidget/widget/index.test.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CurrencyInput onBlur Formatting Fails for Values Below 1000

1 participant