srashtisj srashtisj - 1 month ago 35
TypeScript Question

Wijmo wj-input-date not working if value = null

I'm using wijmo input date for date masking with Angular2 and typescript

<wj-input-date [value]="_note.StartDate" [format]="'d'" [mask]="'99/99/9999'" class="ibox1 rightalign"></wj-input-date>


It's working when I use it like this,

constructor( ...
{
if (this._note.StartDate != null) { this._note.StartDate = new Date(this._note.StartDate.toString()); }
else { this._note.StartDate = new Date(); }
}


but, I don't want anything if value is null, like this

constructor(...
{
if (this._note.StartDate != null) { this._note.StartDate = new Date(this._note.StartDate.toString()); }
}


but, it's giving exception "Assertion failed in Wijmo: Date expected."

Answer

Use [required]="false" and remove [mask]="'99/99/9999'". _note.StartDate should be Date type.

<wj-input-date [(value)]="_note.StartDate" [format]="'d'"  class="ibox1 rightalign" [required]="false"></wj-input-date>