Просмотр исходного кода

fix(admin-ui): Fix affix logic of CurrencyInputComponent

Relates to #971
Michael Bromley 4 лет назад
Родитель
Сommit
bcb57b0520

+ 7 - 1
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 : '')));