Skip to content

Commit 3a8b490

Browse files
author
mashm
committed
Fixed issue with percentage and currency values not displaying correctly in read-only mode
1 parent 9ae8b7a commit 3a8b490

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div *ngIf="displayMode$; else noDisplayMode">
2-
<component-mapper *ngIf="bVisible$ !== false" name="FieldValueList" [props]="{ label$, value$, displayMode$ }"></component-mapper>
2+
<component-mapper *ngIf="bVisible$ !== false" name="FieldValueList" [props]="{ label$, value$: formattedValue, displayMode$ }"></component-mapper>
33
</div>
44
<ng-template #noDisplayMode>
55
<div *ngIf="bHasForm$; else noEdit">

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
@@ -9,8 +9,9 @@ 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 } from '../../../_helpers/currency-utils';
12+
import { getCurrencyCharacters, getCurrencyOptions } from '../../../_helpers/currency-utils';
1313
import { PConnFieldProps } from '../../../_types/PConnProps.interface';
14+
import { format } from '../../../_helpers/formatters';
1415

1516
interface CurrrencyProps extends PConnFieldProps {
1617
// If any, enter additional props that only exist on Currency here
@@ -55,6 +56,7 @@ export class CurrencyComponent implements OnInit, OnDestroy {
5556
currDec: string;
5657
inputMode: any;
5758
decimalPrecision: number | undefined;
59+
formattedValue: string;
5860

5961
constructor(
6062
private angularPConnect: AngularPConnectService,
@@ -136,6 +138,11 @@ export class CurrencyComponent implements OnInit, OnDestroy {
136138
this.currSep = theSymbols.theDigitGroupSeparator;
137139
this.currDec = theSymbols.theDecimalIndicator;
138140

141+
if (this.displayMode$ === 'DISPLAY_ONLY' || this.displayMode$ === 'STACKED_LARGE_VAL') {
142+
const theCurrencyOptions = getCurrencyOptions(currencyISOCode);
143+
this.formattedValue = format(this.configProps$.value, this.pConn$?.getComponentName()?.toLowerCase(), theCurrencyOptions);
144+
}
145+
139146
// timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
140147
setTimeout(() => {
141148
if (this.configProps$.required != null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div *ngIf="displayMode$; else noDisplayMode">
2-
<component-mapper *ngIf="bVisible$ !== false" name="FieldValueList" [props]="{ label$, value$, displayMode$ }"></component-mapper>
2+
<component-mapper *ngIf="bVisible$ !== false" name="FieldValueList" [props]="{ label$, value$: formattedValue, displayMode$ }"></component-mapper>
33
</div>
44
<ng-template #noDisplayMode>
55
<div *ngIf="bHasForm$; else noEdit">

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ 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 } from '../../../_helpers/currency-utils';
12+
import { getCurrencyCharacters, getCurrencyOptions } from '../../../_helpers/currency-utils';
1313
import { PConnFieldProps } from '../../../_types/PConnProps.interface';
14+
import { format } from '../../../_helpers/formatters';
1415

1516
interface PercentageProps extends PConnFieldProps {
1617
showGroupSeparators?: string;
1718
decimalPrecision?: number;
19+
currencyISOCode?: string;
1820
// If any, enter additional props that only exist on Percentage here
1921
}
2022

@@ -51,6 +53,9 @@ export class PercentageComponent implements OnInit, OnDestroy {
5153
inputMode: any;
5254
decimalPrecision: number | undefined;
5355
fieldControl = new FormControl<number | null>(null, null);
56+
actionsApi: Object;
57+
propName: string;
58+
formattedValue: string;
5459

5560
constructor(
5661
private angularPConnect: AngularPConnectService,
@@ -119,12 +124,21 @@ export class PercentageComponent implements OnInit, OnDestroy {
119124
}
120125
this.helperText = this.configProps$.helperText;
121126
this.placeholder = this.configProps$.placeholder || '';
127+
const currencyISOCode = this.configProps$?.currencyISOCode ?? '';
122128
const showGroupSeparators = this.configProps$.showGroupSeparators;
123129

124130
const theSymbols = getCurrencyCharacters('');
125131
this.currDec = theSymbols.theDecimalIndicator || '2';
126132
this.currSep = showGroupSeparators ? theSymbols.theDigitGroupSeparator : '';
127133

134+
this.actionsApi = this.pConn$.getActionsApi();
135+
this.propName = this.pConn$.getStateProps().value;
136+
137+
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);
140+
}
141+
128142
// timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
129143
setTimeout(() => {
130144
if (this.configProps$.required != null) {

packages/angular-sdk-components/src/lib/_helpers/formatters/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ export function format(value, type, options = {}): string {
7575
break;
7676
}
7777

78+
case 'percentage': {
79+
const defaultOptions = { locale: getLocale(), decPlaces: 2 };
80+
const params = { ...defaultOptions, ...options };
81+
formattedValue = Currency.Percentage(value, params);
82+
break;
83+
}
84+
7885
case 'decimal': {
7986
const defaultOptions = { locale: getLocale(), decPlaces: 2 };
8087
const params = { ...defaultOptions, ...options };

0 commit comments

Comments
 (0)