I have a record where no End Date has been defined. I can not figure out how to set the myDatePicker such that the place holder is shown
to be clear, this is the control I am using
https://github.com/kekeh/angular-mydatepicker/wiki
import { Component, OnInit , AfterViewInit
, Input, Output, SimpleChanges
, ElementRef, EventEmitter, ViewChild} from '@angular/core';
import { ReactiveFormsModule, FormBuilder, FormGroup, FormArray, FormControl, ValidatorFn } from '@angular/forms';
import { IMyDpOptions, IMyDateModel, IMyDate } from 'mydatepicker';
import { MatIconRegistry } from '@angular/material/icon';
import { Observable,forkJoin, combineLatest } from 'rxjs';
import { distinctUntilKeyChanged, pluck
, switchMap ,tap, map} from 'rxjs/operators';
import { DomSanitizer } from '@angular/platform-browser';
import {CashFlow2 } from '../cash-flow2'
import {cashFlowService } from '../services/cash-flow.service';
import { sbList} from '../../list-management/sbList';
import { sbListEntry} from '../../list-management/sbListEntry';
import { ListManagementService } from '../../list-management/list-management.service';
@Component({
selector: 'app-cashflow-detail',
templateUrl: './cashflow-detail.component.html',
styleUrls: ['./cashflow-detail.component.css']
})
export class CashflowDetailComponent implements OnInit, AfterViewInit {
myFormGroup: FormGroup;
myCashFlow: CashFlow2;
public myForm$ : Observable<any>;
public vm$ : Observable<any>;
public cfTypes$ : Observable<sbList >;
public myDatePickerOptions: IMyDpOptions = {
todayBtnTxt: 'Today',
dateFormat: 'mm/dd/yyyy',
firstDayOfWeek: 'su',
sunHighlight: true,
satHighlight: true,
inline: false,
height: '25px'
};
@ViewChild('OuterDiv', { static :false } ) private cfDetailDiv_: ElementRef;
@Output() itemOUT = new EventEmitter<CashFlow2>();
constructor(private fb: FormBuilder
, private iconRegistry: MatIconRegistry
, private sanitizer: DomSanitizer
, private cashFlowService : cashFlowService
, private listService : ListManagementService) {
}
ngOnInit(): void {
this.iconRegistry.addSvgIconSet(
this.sanitizer.bypassSecurityTrustResourceUrl('edit/mdi.svg'));
this.iconRegistry.addSvgIconSet(
this.sanitizer.bypassSecurityTrustResourceUrl('edit/mdi.svg'));
this.cfTypes$ = this.listService.getListByName('CashFlowType').pipe(
tap( data => console.log('just asked for the cfType list'))
);
this.vm$.combineLatest(
[
this.myItem
, this.myForm$
, this.cfTypes$
]
).pipe(
map( ([cashFlow,form, cfTypes ]) => ({cashFlow, form, cfTypes}) )
,tap( ( data ) => console.log(data.cfTypes) )
)
}
ngAfterViewInit(){
}
ngOnChanges(changes : SimpleChanges){
console.log( 'myitem was changed' );
console.log( changes);
if (changes.myItem && changes.myItem.currentValue) {
console.log( '****myitem was changed');
this.setMyItem(changes.myItem.currentValue);
}
}
//build the form based on a cashflow
buildForm(cf_: CashFlow2): void {
//return;
this.myFormGroup = null;
this.myCashFlow = cf_;
if (cf_ == null) { return;}
this.myFormGroup = this.fb.group({
cashFlowName: this.myCashFlow.Name,
// here i need to assign **something** to the date picker if the
// value is NULL so it does not display NaaN, NaaN, NaaN
startDate: this.threePartDateFromDate( this.myCashFlow.StartDate),
endDate: this.threePartDateFromDate(this.myCashFlow.EndDate),
description : this.myCashFlow.Description ,
cashFlowType: this.myCashFlow.CashFlowType
});
//subscribe to value changes on form
this.myForm$ = this.myFormGroup.valueChanges.
switchMap( data => {
this.myCashFlow = data;
this.itemOUT.emit(data);
return data;
});
}//buildform
public setMyItem(value:CashFlow2){
console.log('inside setter',value);
this.buildForm(this.myItem);
this.cfDetailDiv_.nativeElement.style.visibility='';
}
//necessary for the datepicker
threePartDateFromDate(d_: string): any {
const date_ = new Date(d_);
console.log(d_);
if(d_ == undefined ){
console.log('date missing');
return {
date: {
year: 0,
month: 0,
day: 0}
}
}
return {
date: {
year: date_.getFullYear(),
month: date_.getMonth()+1,
day: date_.getDate()}
}
}
}
the value is coming to me as undefined. I have tried settting to undefine - this shows NaaN, NaaN, NaaN in the control I have tried setting to {0,0,0}, this shows 0,0,0 in the control