From b02b454abdf42e0575f29f4bff0d727e358131a0 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Mon, 8 Jul 2019 06:44:53 -0700 Subject: [PATCH 1/1] 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 Signed-off-by: Galen Charlton --- .../app/share/combobox/combobox.component.ts | 10 +++++---- .../date-select/date-select.component.html | 1 + .../date-select/date-select.component.ts | 21 +++++++++++-------- 3 files changed, 19 insertions(+), 13 deletions(-) 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 9277bb060e..2139e5b69e 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 @@ -107,8 +107,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, @@ -155,14 +156,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('')); } @@ -232,6 +231,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. @@ -313,7 +313,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 0ff48314c1..80f0188482 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 @@ -15,6 +15,7 @@ name="{{fieldName}}" [disabled]="disabled" [required]="required" + (blur)="propagateTouch()" [(ngModel)]="current" (keyup.enter)="onDateEnter()" (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 ec35601928..66d363af15 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 @@ -58,8 +58,9 @@ export class DateSelectComponent implements OnInit, ControlValueAccessor { return date; } - // Stub function required by ControlValueAccessor + // Stub functions required by ControlValueAccessor propagateChange = (_: any) => {}; + propagateTouch = () => {}; constructor() { this.onChangeAsDate = new EventEmitter(); @@ -78,11 +79,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); } } @@ -126,8 +123,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() + }; } } @@ -135,7 +136,9 @@ export class DateSelectComponent implements OnInit, ControlValueAccessor { this.propagateChange = fn; } - registerOnTouched() { } + registerOnTouched(fn) { + this.propagateTouch = fn; + } } -- 2.43.2