-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format currency input with commas in household input #941
Conversation
Thanks @abhcs - how does this handle user input? Just to check that if a user sees commas and changes the value to a string including commas that this wouldn't break the app. |
The formatter property changes the display string on each event. The user will be unable to type the string
Note that the current component also reformats the display string similarly but does not add commas. This is an unavoidable side-effect of "formatting in real time" (#178); see also the formatter example at https://ant.design/components/input-number. If one were to directly paste the string |
This looks like a great change. I tested locally and can see that your edits do handle the comma properly, as well as clipping out garbage values. That said, per the video I've included here, the edits don't properly format an input sub-dollar unit divisible by ten; for instance, if I input "$15,000.30", it shortens this to "$15,000.3". So, to proceed, I'm wondering if you'd be willing to do the following:
Thanks so much for your contributions to the app! Screen.Recording.2023-12-11.at.4.43.43.PM.mov |
Screen.Recording.2023-12-11.at.4.43.43.PM.movHopefully the video uploaded correctly in this comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, I should've left my comments here, but please see my comments on the PR itself
In the The abstraction of ![]()
Since pull request #892, the default is displayed as
Done.
You are welcome. |
The new commits should fix #928. Now, I am using the formatter property for all floats. Despite age being a float, the trailing zeros get stripped. |
I've been digging into this to see if we can get it to display two decimal places only after the user clicks outside the input, as doing it before prevents the user from inputting a second decimal place without hitting backspace. I'll come back to it tomorrow. |
Please check the latest commit. It may do what you are looking for; otherwise, we can revert it. It uses a strange combination of formatter and precision, which seems to work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've taken the liberty of making a minor edit: In Ant Design, the precision
feel is overridden whenever a formatter
is present, meaning your last commit unfortunately didn't have its intended impact. However, there's a pretty hidden userTyping
param that allows for conditional formatting based on whether the user's actively engaging with the box, so I've edited it to format decimals only when the user isn't typing.
Thanks again for digging deep into antd's docs, @abhcs.
Edit: Just waiting to push until the checks finish
The docs say that |
Very strange, perhaps your version was different from mine? When I installed and ran yours locally, the overriding did occur…not sure why.
… On Dec 13, 2023, at 8:26 PM, Abhishek Singh ***@***.***> wrote:
The docs say that precision is overridden by formatter but the solution was working! It was allowing the user to type an arbitrary number of fractional digits but the precision was getting applied on blur, i.e., not typing. I think that using userTyping is a better solution though. See PR #962 <#962>.
—
Reply to this email directly, view it on GitHub <#941 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ADSK7W6YBLFSZW4HLS7VXXTYJJPWFAVCNFSM6AAAAABALOLR46VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJVGAYDSOJUHE>.
You are receiving this because you modified the open/close state.
|
Yeah, its best not to depend on undocumented quirks in any case. So |
Ah, that could be it. We’ve had cases before where Safari will do one thing and all other browsers do another for some reason.
… On Dec 13, 2023, at 20:32, Abhishek Singh ***@***.***> wrote:
Yeah, its best not to depend on undocumented quirks in any case. So userTyping is a better solution. Maybe it was browser-specific. I am using Safari.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you modified the open/close state.
|
Fixed #178 by using the formatter property in ant-design InputNumber component. Renamed locale en to en-GB, the standard Unicode identifier for the English language in the UK region (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale for details). Improved the interface for locale-related functions with better names and documentation.
Tested in UK and US locales to verify that currencies are displayed properly in inputs and charts.
![Screenshot 2023-12-07 at 11 41 45 AM](https://private-user-images.githubusercontent.com/31144719/288845316-c46c4a55-ac76-4019-bc90-fde9021d27b3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2NzE0ODYsIm5iZiI6MTczOTY3MTE4NiwicGF0aCI6Ii8zMTE0NDcxOS8yODg4NDUzMTYtYzQ2YzRhNTUtYWM3Ni00MDE5LWJjOTAtZmRlOTAyMWQyN2IzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE2VDAxNTk0NlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTliYTUxOWQzMzQyNDg0OWMwY2ZhNmZmZTg2ZDBkNjJiZjYxOGMxZTdhOTY0YzM0NzNhZWViZTJhZTZlZWUwMmQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.ac6GcaeDt62NpdzvZodKCMO4MQrtoWwtkEekqi3D3jw)
🤖[deprecated] Generated by Copilot at 63f4416
Summary
🌐💷📊
This pull request improves the localization of currency values and plotly charts in the policy engine app. It introduces two new functions,
localeCode
andcurrencyCode
, to get the appropriate codes for a given country. It also updates theVariableEditor
component and the output charts to use these functions and the nativetoLocaleString
method of numbers. It also renames and updates the UK English plotly locale module.Walkthrough
currencyString
andlocaleString
functions withlocaleCode
andcurrencyCode
functions insrc/api/language.js
to return locale and currency codes for a given country id (link)src/pages/household/input/VariableEditor.jsx
, update theformatter
prop of theInputNumber
component in theHouseholdVariableEntityInput
function (link, link)src/pages/policy/output/AverageImpactByDecile.jsx
, update thetext
prop of thebar
trace in theAverageImpactByDecilePlot
function (link, link)src/pages/policy/output/AverageImpactByWealthDecile.jsx
, update thetext
prop of thebar
trace in theAverageImpactByWealthDecilePlot
function (link, link)src/pages/policy/output/AverageImpactByDecile.jsx
, update thelocale
prop of thePlot
component in theAverageImpactByDecilePlot
function (link)src/pages/policy/output/AverageImpactByWealthDecile.jsx
, update thelocale
prop of thePlot
component in theAverageImpactByWealthDecilePlot
function (link)src/pages/policy/output/BudgetaryImpact.jsx
, update thelocale
prop of thePlot
component in theBudgetaryImpactPlot
function (link, link)src/pages/policy/output/DetailedBudgetaryImpact.jsx
, update thelocale
prop of thePlot
component in theDetailedBudgetaryImpactPlot
function (link, link)src/plotly_locales/locale-en.js
tosrc/plotly_locales/locale-en-gb.js
and change thename
property of theloc_en
module toen-GB
to reflect the correct locale code for the UK English plotly locale (link)src/redesign/components/PolicyEngine.jsx
to use the renamedloc_en_gb
module (link, link)