From bcb57b052053a2cc38d6ab003cd7025398dfc341 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Thu, 8 Jul 2021 12:16:08 +0200 Subject: [PATCH] fix(admin-ui): Fix affix logic of CurrencyInputComponent Relates to #971 --- .../components/currency-input/currency-input.component.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/admin-ui/src/lib/core/src/shared/components/currency-input/currency-input.component.ts b/packages/admin-ui/src/lib/core/src/shared/components/currency-input/currency-input.component.ts index 9ef6b1162c..f517113928 100644 --- a/packages/admin-ui/src/lib/core/src/shared/components/currency-input/currency-input.component.ts +++ b/packages/admin-ui/src/lib/core/src/shared/components/currency-input/currency-input.component.ts @@ -53,12 +53,18 @@ export class CurrencyInputComponent implements ControlValueAccessor, OnInit, OnC return ''; } const locale = languageCode.replace(/_/g, '-'); + const parts = new Intl.NumberFormat(locale, { + style: 'currency', + currency: currencyCode, + currencyDisplay: 'symbol', + }).formatToParts(); + const NaNString = parts.find(p => p.type === 'nan')?.value ?? 'NaN'; const localised = new Intl.NumberFormat(locale, { style: 'currency', currency: currencyCode, currencyDisplay: 'symbol', }).format(undefined as any); - return localised.indexOf('NaN') > 0; + return localised.indexOf(NaNString) > 0; }), ); this.prefix$ = shouldPrefix$.pipe(map(shouldPrefix => (shouldPrefix ? this.currencyCode : '')));