Skip to content

Commit a16d821

Browse files
dobromirtsLipata
andauthored
fix(date-time-editor): handle iso date string for mask value 16.1.x (#14033)
* fix(date-time-editor): handle iso date string for mask value 16.1.x * chore(*): add test for iso string date --------- Co-authored-by: Nikolay Alipiev <[email protected]>
1 parent 6c77177 commit a16d821

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

projects/igniteui-angular/src/lib/directives/date-time-editor/date-time-editor.directive.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,26 @@ describe('IgxDateTimeEditor', () => {
378378
inputElement = fixture.debugElement.query(By.css('input'));
379379
dateTimeEditorDirective = inputElement.injector.get(IgxDateTimeEditorDirective);
380380
});
381+
381382
it('should properly update mask with inputFormat onInit', () => {
382383
fixture = TestBed.createComponent(IgxDateTimeEditorBaseTestComponent);
383384
fixture.detectChanges();
384385
expect(fixture.componentInstance.dateEditor.elementRef.nativeElement.value).toEqual('09/11/2009');
385386
});
387+
388+
it('should update value and mask according to the display format and ISO string date as value', () => {
389+
fixture.componentInstance.dateTimeFormat = 'dd/MM/yy';
390+
fixture.componentInstance.displayFormat = 'shortDate';
391+
dateTimeEditorDirective.value = new Date(2003, 3, 5).toISOString();
392+
fixture.detectChanges();
393+
inputElement.triggerEventHandler('focus', {});
394+
fixture.detectChanges();
395+
expect(dateTimeEditorDirective.mask).toEqual('00/00/00');
396+
expect(inputElement.nativeElement.value).toEqual('05/04/03');
397+
UIInteractions.simulateTyping('1', inputElement);
398+
expect(inputElement.nativeElement.value).toEqual('15/04/03');
399+
});
400+
386401
it('should correctly display input format during user input', () => {
387402
fixture.componentInstance.dateTimeFormat = 'dd/MM/yy';
388403
fixture.detectChanges();

projects/igniteui-angular/src/lib/directives/date-time-editor/date-time-editor.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnCh
552552

553553
private getMaskedValue(): string {
554554
let mask = this.emptyMask;
555-
if (DateTimeUtil.isValidDate(this.value)) {
555+
if (DateTimeUtil.isValidDate(this.value) || DateTimeUtil.parseIsoDate(this.value)) {
556556
for (const part of this._inputDateParts) {
557557
if (part.type === DatePart.Literal) {
558558
continue;

0 commit comments

Comments
 (0)