import {ContextMenuModule} from '@eg/share/context-menu/context-menu.module';
import {FileReaderComponent} from '@eg/share/file-reader/file-reader.component';
import {IntervalInputComponent} from '@eg/share/interval-input/interval-input.component';
+import {DateSelectNativeComponent} from '@eg/share/date-select-native/date-select-native.component';
@NgModule({
DateTimeSelectComponent,
FileReaderComponent,
IdlClassTemplateDirective,
+ DateSelectNativeComponent,
IntervalInputComponent,
],
imports: [
DateTimeSelectComponent,
ContextMenuModule,
FileReaderComponent,
+ DateSelectNativeComponent,
IntervalInputComponent,
],
})
--- /dev/null
+import {Component, OnInit, Input, Output, ViewChild, EventEmitter, forwardRef} from '@angular/core';
+import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
+import {DateUtil} from '@eg/share/util/date';
+
+
+@Component({
+ selector: 'eg-date-select-native',
+ templateUrl: './date-select-native.component.html',
+ providers: [{
+ provide: NG_VALUE_ACCESSOR,
+ useExisting: forwardRef(() => DateSelectNativeComponent),
+ multi: true
+ }]
+})
+export class DateSelectNativeComponent implements OnInit, ControlValueAccessor {
+
+ static domAutoId = 1;
+
+ @Input() fieldName = '';
+ @Input() required = false;
+ @Input() disabled = false; // Also works for readOnly
+ @Input() min = ''; // YYYY-MM-DD
+ @Input() max = ''; // YYYY-MM-DD
+ @Input() domId = 'eg-date-select-native-' + DateSelectNativeComponent.domAutoId++;
+
+ // Emits YYYY-MM-DD on value change, null on empty.
+ @Output() dateChange: EventEmitter<string> = new EventEmitter<string>();
+
+ // Stub functions required by ControlValueAccessor
+ propagateChange = (_: any) => {};
+ propagateTouch = () => {};
+
+ constructor() { }
+
+ ngOnInit() { }
+
+ input(): HTMLInputElement {
+ return document.getElementById(this.domId) as HTMLInputElement;
+ }
+
+ inputChange(evt: Event) {
+ const value = this.input().value;
+ this.dateChange.emit(value || null);
+ this.propagateChange(value);
+ }
+
+ writeValue(ymd: string) {
+ if (this.input()) {
+ this.input().value = ymd;
+ }
+ }
+
+ registerOnChange(fn) {
+ this.propagateChange = fn;
+ }
+
+ registerOnTouched(fn) {
+ this.propagateTouch = fn;
+ }
+}
+
+