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 3532b224d2..5b825d1da5 100644 --- a/lib/core/form/components/widgets/amount/amount.widget.spec.ts +++ b/lib/core/form/components/widgets/amount/amount.widget.spec.ts @@ -17,7 +17,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { FormFieldModel } from './../core/form-field.model'; -import { AmountWidgetComponent } from './amount.widget'; +import { AmountWidgetComponent, ADF_AMOUNT_SETTINGS } from './amount.widget'; import { setupTestBed } from '../../../../testing/setupTestBed'; import { CoreModule } from '../../../../core.module'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; @@ -77,3 +77,38 @@ describe('AmountWidgetComponent', () => { }); }); + +describe('AmountWidgetComponent settings', () => { + let widget: AmountWidgetComponent; + let fixture: ComponentFixture; + + setupTestBed({ + imports: [ + NoopAnimationsModule, + CoreModule.forRoot() + ], + providers: [ + { + provide: ADF_AMOUNT_SETTINGS, + useValue: { + showReadonlyPlaceholder: true + } + } + ] + }); + + beforeEach(() => { + fixture = TestBed.createComponent(AmountWidgetComponent); + + widget = fixture.componentInstance; + }); + + it('should display placeholder via injected settings', () => { + const field: any = { + readOnly: true, + placeholder: 'some placeholder' + }; + widget.field = field; + expect(widget.placeholder).toBe('some placeholder'); + }); +}); diff --git a/lib/core/form/components/widgets/amount/amount.widget.ts b/lib/core/form/components/widgets/amount/amount.widget.ts index 0d4f6425b2..c91b91756c 100644 --- a/lib/core/form/components/widgets/amount/amount.widget.ts +++ b/lib/core/form/components/widgets/amount/amount.widget.ts @@ -17,10 +17,16 @@ /* tslint:disable:component-selector */ -import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { Component, OnInit, ViewEncapsulation, InjectionToken, Inject, Optional } from '@angular/core'; import { FormService } from './../../../services/form.service'; import { baseHost , WidgetComponent } from './../widget.component'; +export interface AmountWidgetSettings { + showReadonlyPlaceholder: boolean; +} + +export const ADF_AMOUNT_SETTINGS = new InjectionToken('adf-amount-settings'); + @Component({ selector: 'amount-widget', templateUrl: './amount.widget.html', @@ -31,20 +37,32 @@ import { baseHost , WidgetComponent } from './../widget.component'; export class AmountWidgetComponent extends WidgetComponent implements OnInit { static DEFAULT_CURRENCY: string = '$'; + private showPlaceholder = true; currency: string = AmountWidgetComponent.DEFAULT_CURRENCY; get placeholder(): string { - return !this.field.readOnly ? this.field.placeholder : ''; + return this.showPlaceholder ? this.field.placeholder : ''; } - constructor(public formService: FormService) { + constructor( + public formService: FormService, + @Inject(ADF_AMOUNT_SETTINGS) + @Optional() + private settings: AmountWidgetSettings + ) { super(formService); } ngOnInit() { - if (this.field && this.field.currency) { - this.currency = this.field.currency; + if (this.field) { + if (this.field.currency) { + this.currency = this.field.currency; + } + + if (this.field.readOnly) { + this.showPlaceholder = this.settings && this.settings.showReadonlyPlaceholder; + } } }