Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix watcher for values of the date type #431

Merged
merged 3 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/watcher-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class WatcherHelper {
}

private _isDifferentValues(oldValue: any, newValue: any, deepCheck: boolean) {
if (deepCheck && newValue instanceof (Object) && oldValue instanceof (Object)) {
if (deepCheck && newValue instanceof (Object) && oldValue instanceof (Object) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to extract groupable conditions.
if(deepCheck && isObjectValues && !isDateValues)

!(oldValue instanceof Date && newValue instanceof Date)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add round brackets after instanceof (or remove it from other conditions)

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));
}));
});