LP1840782 <eg-date-select-native /> component
authorBill Erickson <berickxx@gmail.com>
Thu, 7 Oct 2021 18:58:32 +0000 (14:58 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 7 Oct 2021 18:58:32 +0000 (14:58 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/date-select-native/date-select-native.component.ts

index 5fe5aa7..42f2da3 100644 (file)
@@ -13,7 +13,6 @@ import {DateUtil} from '@eg/share/util/date';
   }]
 })
 export class DateSelectNativeComponent implements OnInit, ControlValueAccessor {
-
     static domAutoId = 1;
 
     @Input() fieldName = '';
@@ -25,6 +24,10 @@ export class DateSelectNativeComponent implements OnInit, ControlValueAccessor {
 
     // Emits YYYY-MM-DD on value change, null on empty.
     @Output() dateChange: EventEmitter<string> = new EventEmitter<string>();
+    // Emits Date object
+    @Output() dateChangeAsDate: EventEmitter<Date> = new EventEmitter<Date>();
+    // Emits ISO8601 date string
+    @Output() dateChangeAsIso: EventEmitter<string> = new EventEmitter<string>();
 
     // Stub functions required by ControlValueAccessor
     propagateChange = (_: any) => {};
@@ -40,8 +43,20 @@ export class DateSelectNativeComponent implements OnInit, ControlValueAccessor {
 
     inputChange(evt: Event) {
         const value = this.input().value;
-        this.dateChange.emit(value || null);
         this.propagateChange(value);
+
+        if (!value) {
+            this.dateChange.emit(null);
+            this.dateChangeAsDate.emit(null);
+            this.dateChangeAsIso.emit(null);
+
+        } else {
+
+            let date = DateUtil.localDateFromYmd(value);
+            this.dateChange.emit(value);
+            this.dateChangeAsDate.emit(date);
+            this.dateChangeAsIso.emit(date.toISOString());
+        }
     }
 
     writeValue(ymd: string) {