From: Jane Sandberg Date: Mon, 8 Jul 2019 13:44:53 +0000 (-0700) Subject: LP1831390: Fixing implementation of registerOnTouch X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fberick%2Flp1831390-ang-form-control-value-accessor-2;p=working%2FEvergreen.git LP1831390: Fixing implementation of registerOnTouch This commit ensures that the onTouch callback is called on the blur event, per the official Angular documentation. Also improves the display of default values in the datepicker Signed-off-by: Jane Sandberg Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts index 79042c63c1..d391244193 100644 --- a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts +++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts @@ -97,8 +97,9 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit { // and display. Default version trims leading/trailing spaces. formatDisplayString: (e: ComboboxEntry) => string; - // Stub function required by ControlValueAccessor + // Stub functions required by ControlValueAccessor propagateChange = (_: any) => {}; + propagateTouch = () => {}; constructor( private elm: ElementRef, @@ -120,14 +121,12 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit { } onClick($event) { - this.registerOnTouched(); this.click$.next($event.target.value); } openMe($event) { // Give the input a chance to focus then fire the click // handler to force open the typeahead - this.registerOnTouched(); this.elm.nativeElement.getElementsByTagName('input')[0].focus(); setTimeout(() => this.click$.next('')); } @@ -197,6 +196,7 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit { this.selectorChanged( {item: this.selected, preventDefault: () => true}); } + this.propagateTouch(); } // Fired by the typeahead to inform us of a change. @@ -277,7 +277,9 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit { this.propagateChange = fn; } - registerOnTouched() { } + registerOnTouched(fn) { + this.propagateTouch = fn; + } } diff --git a/Open-ILS/src/eg2/src/app/share/date-select/date-select.component.html b/Open-ILS/src/eg2/src/app/share/date-select/date-select.component.html index 7e65f7628e..06b31ef9a7 100644 --- a/Open-ILS/src/eg2/src/app/share/date-select/date-select.component.html +++ b/Open-ILS/src/eg2/src/app/share/date-select/date-select.component.html @@ -10,6 +10,7 @@ name="{{fieldName}}" [disabled]="_disabled" [required]="required" + (blur)="propagateTouch()" [(ngModel)]="current" (dateSelect)="onDateSelect($event)"/>
diff --git a/Open-ILS/src/eg2/src/app/share/date-select/date-select.component.ts b/Open-ILS/src/eg2/src/app/share/date-select/date-select.component.ts index d4802e193b..4aa1780dc9 100644 --- a/Open-ILS/src/eg2/src/app/share/date-select/date-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/date-select/date-select.component.ts @@ -37,8 +37,9 @@ export class DateSelectComponent implements OnInit, ControlValueAccessor { @Output() onChangeAsIso: EventEmitter; @Output() onChangeAsYmd: EventEmitter; - // Stub function required by ControlValueAccessor + // Stub functions required by ControlValueAccessor propagateChange = (_: any) => {}; + propagateTouch = () => {}; constructor() { this.onChangeAsDate = new EventEmitter(); @@ -56,11 +57,7 @@ export class DateSelectComponent implements OnInit, ControlValueAccessor { } if (this.initialDate) { - this.current = { - year: this.initialDate.getFullYear(), - month: this.initialDate.getMonth() + 1, - day: this.initialDate.getDate() - }; + this.writeValue(this.initialDate); } } @@ -83,8 +80,12 @@ export class DateSelectComponent implements OnInit, ControlValueAccessor { } writeValue(value: Date) { - if (value !== undefined) { - this.initialDate = value; + if (value) { + this.current = { + year: value.getFullYear(), + month: value.getMonth() + 1, + day: value.getDate() + }; } } @@ -92,7 +93,9 @@ export class DateSelectComponent implements OnInit, ControlValueAccessor { this.propagateChange = fn; } - registerOnTouched() { } + registerOnTouched(fn) { + this.propagateTouch = fn; + } }