Skip to content

Commit

Permalink
feat: add more decimal places to CurrencyInput
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaHariprasad5123 committed May 24, 2024
1 parent 88111ac commit 19bcbbd
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ describe("Utilities - ", () => {
[
[0, "123.12", "123"],
[1, "123.12", "123.1"],
[2, "123.12", "123.12"],
[2, "123456.12", "123456.12"],
[1, "123456.12", "123456.1"],
[0, "123456.12", "123456"],
Expand All @@ -98,6 +97,18 @@ describe("Utilities - ", () => {
[2, "0.22123123", "0.22"],
[1, "0.22123123", "0.2"],
[0, "0.22123123", "0"],
[3, "123.12345", "123.123"],
[4, "123.12345", "123.1234"],
[5, "123.12345", "123.12345"],
[6, "123.12345", "123.12345"],
[3, "0.123456", "0.123"],
[4, "0.123456", "0.1234"],
[5, "0.123456", "0.12345"],
[6, "0.123456", "0.123456"],
[3, "123456.123456", "123456.123"],
[4, "123456.123456", "123456.1234"],
[5, "123456.123456", "123456.12345"],
[6, "123456.12345678", "123456.123456"],
].forEach((d) => {
expect(limitDecimalValue(d[0] as number, d[1] as string)).toBe(d[2]);
});
Expand Down
18 changes: 13 additions & 5 deletions app/client/src/widgets/CurrencyInputWidget/component/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,20 @@ export const limitDecimalValue = (decimals = 0, value = "") => {
return value.split(decimalSeperator).shift() || "";
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
const decimalValueArray = value.split(decimalSeperator);
return (
decimalValueArray[0] +
decimalSeperator +
decimalValueArray[1].slice(0, decimals)
);
if (decimalValueArray.length > 1) {
return (
decimalValueArray[0] +
decimalSeperator +
decimalValueArray[1].slice(0, decimals)
);
} else {
return decimalValueArray[0];
}
default:
return value;
}
Expand Down
16 changes: 16 additions & 0 deletions app/client/src/widgets/CurrencyInputWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,22 @@ class CurrencyInputWidget extends BaseInputWidget<
label: "2",
value: 2,
},
{
label: "3",
value: 3,
},
{
label: "4",
value: 4,
},
{
label: "5",
value: 5,
},
{
label: "6",
value: 6,
},
],
isJSConvertible: true,
isBindProperty: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,22 @@ const PROPERTIES = {
label: "2",
value: 2,
},
{
label: "3",
value: 3,
},
{
label: "4",
value: 4,
},
{
label: "5",
value: 5,
},
{
label: "6",
value: 6,
},
],
hidden: (...args: HiddenFnParams) =>
getSchemaItem(...args).fieldTypeNotMatches(FieldType.CURRENCY_INPUT),
Expand Down

0 comments on commit 19bcbbd

Please sign in to comment.