Skip to content

Commit

Permalink
Merge pull request #431 from dxvladislavvolkov/fix-watcher
Browse files Browse the repository at this point in the history
Fix watcher for values of the date type
  • Loading branch information
dxvladislavvolkov committed Apr 11, 2017
2 parents 255001a + fb73fd6 commit 8a8355b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/core/watcher-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export class WatcherHelper {
}

private _isDifferentValues(oldValue: any, newValue: any, deepCheck: boolean) {
if (deepCheck && newValue instanceof (Object) && oldValue instanceof (Object)) {
let isObjectValues = newValue instanceof Object && oldValue instanceof Object,
isDateValues = oldValue instanceof Date && newValue instanceof Date;

if (deepCheck && isObjectValues && !isDateValues) {
return this._checkObjectsFields(newValue, oldValue);
}
return oldValue !== newValue;
Expand Down
24 changes: 23 additions & 1 deletion tests/src/ui/form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
})
class TestContainerComponent {
formData = {
name: 'Unknown'
name: 'Unknown',
date: new Date()
};
@ViewChildren(DxFormComponent) innerWidgets: QueryList<DxFormComponent>;
}
Expand Down Expand Up @@ -114,4 +115,25 @@ describe('DxForm', () => {

expect(formInstance.option('formData.name')).toEqual([2]);
}));

it('should change the value of dxDateBox', async(() => {
TestBed.overrideComponent(TestContainerComponent, {
set: {
template: `
<dx-form [formData]="formData">
</dx-form>
`
}
});
let fixture = TestBed.createComponent(TestContainerComponent);
fixture.detectChanges();

fixture.componentInstance.formData.date = new Date(2017, 0, 1);
fixture.detectChanges();

let formInstance = getWidget(fixture);
let dateBoxInstance = formInstance.getEditor('date');

expect(dateBoxInstance.option('value')).toEqual(new Date(2017, 0, 1));
}));
});

0 comments on commit 8a8355b

Please sign in to comment.