From 22c8d8ef2a5e5f35ca58d55b735c314d8a2e70ae Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 9 May 2024 10:43:27 -0700 Subject: [PATCH] Fix: allow 0 in monetary field (#6658) --- .../common/input/monetary/monetary.component.spec.ts | 9 +++++++++ .../common/input/monetary/monetary.component.ts | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts b/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts index f22a3f53d..30b78dde7 100644 --- a/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts +++ b/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts @@ -74,4 +74,13 @@ describe('MonetaryComponent', () => { expect(component.currency).toEqual('USD') expect(component.monetaryValue).toEqual('') }) + + it('should handle zero values', () => { + component.writeValue('USD0.00') + expect(component.currency).toEqual('USD') + expect(component.monetaryValue).toEqual('0.00') + component.monetaryValue = '0' + component.monetaryValueChange() + expect(component.value).toEqual('USD0.00') + }) }) diff --git a/src-ui/src/app/components/common/input/monetary/monetary.component.ts b/src-ui/src/app/components/common/input/monetary/monetary.component.ts index 56f0dd28e..256dc8c18 100644 --- a/src-ui/src/app/components/common/input/monetary/monetary.component.ts +++ b/src-ui/src/app/components/common/input/monetary/monetary.component.ts @@ -22,8 +22,9 @@ export class MonetaryComponent extends AbstractInputComponent { public get monetaryValue(): string { return this._monetaryValue } - public set monetaryValue(value: string) { - if (value) this._monetaryValue = value + public set monetaryValue(value: any) { + if (value || value?.toString() === '0') + this._monetaryValue = value.toString() } defaultCurrencyCode: string @@ -44,6 +45,9 @@ export class MonetaryComponent extends AbstractInputComponent { public monetaryValueChange(fixed: boolean = false): void { this.monetaryValue = this.parseMonetaryValue(this.monetaryValue, fixed) + if (this.monetaryValue === '0') { + this.monetaryValue = '0.00' + } this.onChange(this.currency + this.monetaryValue) }