Skip to content

Commit 97acf37

Browse files
samhere06mohas22
andauthored
updated formatting of decimal,currency and percentage (#249)
Co-authored-by: mohas22 <[email protected]>
1 parent 0246b0e commit 97acf37

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

packages/angular-sdk-components/src/lib/_components/field/currency/currency.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface CurrrencyProps extends PConnFieldProps {
1717
// If any, enter additional props that only exist on Currency here
1818
currencyISOCode?: string;
1919
allowDecimals: boolean;
20+
formatter?: string;
2021
}
2122

2223
@Component({
@@ -57,6 +58,7 @@ export class CurrencyComponent implements OnInit, OnDestroy {
5758
inputMode: any;
5859
decimalPrecision: number | undefined;
5960
formattedValue: string;
61+
formatter;
6062

6163
constructor(
6264
private angularPConnect: AngularPConnectService,
@@ -137,10 +139,15 @@ export class CurrencyComponent implements OnInit, OnDestroy {
137139
this.currSym = theSymbols.theCurrencySymbol;
138140
this.currSep = theSymbols.theDigitGroupSeparator;
139141
this.currDec = theSymbols.theDecimalIndicator;
142+
this.formatter = this.configProps$.formatter;
140143

141144
if (this.displayMode$ === 'DISPLAY_ONLY' || this.displayMode$ === 'STACKED_LARGE_VAL') {
142145
const theCurrencyOptions = getCurrencyOptions(currencyISOCode);
143-
this.formattedValue = format(this.configProps$.value, this.pConn$?.getComponentName()?.toLowerCase(), theCurrencyOptions);
146+
if (this.formatter) {
147+
this.formattedValue = format(this.value$, this.formatter.toLowerCase(), theCurrencyOptions);
148+
} else {
149+
this.formattedValue = format(this.value$, 'currency', theCurrencyOptions);
150+
}
144151
}
145152

146153
// timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError

packages/angular-sdk-components/src/lib/_components/field/decimal/decimal.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ export class DecimalComponent implements OnInit, OnDestroy {
149149
const theCurrencyOptions = getCurrencyOptions(currencyISOCode);
150150
this.formatter = this.configProps$.formatter;
151151

152-
if (this.formatter === 'Currency') {
152+
if (this.formatter) {
153153
this.formattedValue = format(this.value$, this.formatter.toLowerCase(), theCurrencyOptions);
154154
} else {
155-
this.formattedValue = format(this.value$, this.pConn$.getComponentName()?.toLowerCase(), theCurrencyOptions);
155+
this.formattedValue = format(this.value$, 'decimal', theCurrencyOptions);
156156
}
157157

158158
// timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError

packages/angular-sdk-components/src/lib/_components/field/percentage/percentage.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { AngularPConnectData, AngularPConnectService } from '../../../_bridge/an
99
import { Utils } from '../../../_helpers/utils';
1010
import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component';
1111
import { handleEvent } from '../../../_helpers/event-util';
12-
import { getCurrencyCharacters, getCurrencyOptions } from '../../../_helpers/currency-utils';
12+
import { getCurrencyCharacters } from '../../../_helpers/currency-utils';
1313
import { PConnFieldProps } from '../../../_types/PConnProps.interface';
1414
import { format } from '../../../_helpers/formatters';
1515

@@ -124,7 +124,6 @@ export class PercentageComponent implements OnInit, OnDestroy {
124124
}
125125
this.helperText = this.configProps$.helperText;
126126
this.placeholder = this.configProps$.placeholder || '';
127-
const currencyISOCode = this.configProps$?.currencyISOCode ?? '';
128127
const showGroupSeparators = this.configProps$.showGroupSeparators;
129128

130129
const theSymbols = getCurrencyCharacters('');
@@ -135,8 +134,7 @@ export class PercentageComponent implements OnInit, OnDestroy {
135134
this.propName = this.pConn$.getStateProps().value;
136135

137136
if (this.displayMode$ === 'DISPLAY_ONLY' || this.displayMode$ === 'STACKED_LARGE_VAL') {
138-
const theCurrencyOptions = getCurrencyOptions(currencyISOCode);
139-
this.formattedValue = format(nValue, this.pConn$?.getComponentName()?.toLowerCase(), theCurrencyOptions);
137+
this.formattedValue = format(nValue, 'percentage');
140138
}
141139

142140
// timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError

0 commit comments

Comments
 (0)