Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Updating the model should result in an updated datepicker #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Updating the model should result in an updated datepicker
Conflicts:
	test/date.spec.js
  • Loading branch information
timmipetit committed May 8, 2014
commit b13217e8f9ed62bfb283353d9b29d517f7a8e9fa
1 change: 1 addition & 0 deletions demo/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<body ng-app="ui.date">
<label>Select Date: <input type="text" ui-date ng-model="aDate"></label>
<div>{{aDate}}</div>
<div><a href="" ng-click="aDate.setDate(aDate.getDate()+1);">Increase Date</a></div>
</body>
</html>
8 changes: 8 additions & 0 deletions src/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ angular.module('ui.date', [])
}
element.datepicker("setDate", date);
};

scope.$watch(attrs.ngModel, function() {
var date = controller.$viewValue;
if ( angular.isDefined(date) && date !== null && !angular.isDate(date) ) {
return;
}
controller.$render();
}, true);
}
// If we don't destroy the old one it doesn't update properly when the config changes
element.datepicker('destroy');
Expand Down
13 changes: 13 additions & 0 deletions test/date.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ describe('uiDate', function() {
expect(element.datepicker('getDate')).toEqual(aDate);
});
});
it('should update the datepicker if the model changes', function() {
inject(function($compile, $rootScope) {
var aDate, element;
aDate = new Date(2010, 12, 1);
element = $compile("<input ui-date ng-model='x'/>")($rootScope);
$rootScope.$apply(function() {
$rootScope.x = aDate;
});
aDate.setDate(aDate.getDate()+1);
$rootScope.$apply();
expect(element.datepicker('getDate')).toEqual(aDate);
});
});
it('should put the date in the model', function() {
inject(function($compile, $rootScope) {
var aDate, element;
Expand Down