From 1cb4dfc1b82d44a42fbc0c97967ee4fbdf7fa3d0 Mon Sep 17 00:00:00 2001 From: davidcanonieto Date: Sat, 31 Aug 2019 00:30:13 +0100 Subject: [PATCH] [ADF-4764] Hide placeholder in Amount Widget in readOnly mode (#5035) * [ADF-4764] Hide placeholder in Amount Widget in readOnly mode * add missing return type --- .../widgets/amount/amount.widget.html | 2 +- .../widgets/amount/amount.widget.spec.ts | 20 +++++++++++++++++++ .../widgets/amount/amount.widget.ts | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/core/form/components/widgets/amount/amount.widget.html b/lib/core/form/components/widgets/amount/amount.widget.html index bbeb186a15..8a79272093 100644 --- a/lib/core/form/components/widgets/amount/amount.widget.html +++ b/lib/core/form/components/widgets/amount/amount.widget.html @@ -7,7 +7,7 @@ type="text" [id]="field.id" [required]="isRequired()" - [placeholder]="field.placeholder" + [placeholder]="placeholder" [value]="field.value" [(ngModel)]="field.value" (ngModelChange)="onFieldChanged(field)" diff --git a/lib/core/form/components/widgets/amount/amount.widget.spec.ts b/lib/core/form/components/widgets/amount/amount.widget.spec.ts index 525e3873d7..3532b224d2 100644 --- a/lib/core/form/components/widgets/amount/amount.widget.spec.ts +++ b/lib/core/form/components/widgets/amount/amount.widget.spec.ts @@ -56,4 +56,24 @@ describe('AmountWidgetComponent', () => { expect(widget.currency).toBe(AmountWidgetComponent.DEFAULT_CURRENCY); }); + it('should setup empty placeholder in readOnly mode', () => { + widget.field = new FormFieldModel(null, { + readOnly: true, + placeholder: '1234' + }); + + widget.ngOnInit(); + expect(widget.placeholder).toBe(''); + }); + + it('should setup placeholder when readOnly is false', () => { + widget.field = new FormFieldModel(null, { + readOnly: false, + placeholder: '1234' + }); + + widget.ngOnInit(); + expect(widget.placeholder).toBe('1234'); + }); + }); diff --git a/lib/core/form/components/widgets/amount/amount.widget.ts b/lib/core/form/components/widgets/amount/amount.widget.ts index 41a146ca1a..0d4f6425b2 100644 --- a/lib/core/form/components/widgets/amount/amount.widget.ts +++ b/lib/core/form/components/widgets/amount/amount.widget.ts @@ -34,6 +34,10 @@ export class AmountWidgetComponent extends WidgetComponent implements OnInit { currency: string = AmountWidgetComponent.DEFAULT_CURRENCY; + get placeholder(): string { + return !this.field.readOnly ? this.field.placeholder : ''; + } + constructor(public formService: FormService) { super(formService); }