Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit d956165

Browse files
committed
Fix bug when update the list of available days and months
1 parent 1a0c9f1 commit d956165

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngComboDatePicker",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"authors": [
55
"jfmdev <[email protected]>"
66
],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-combo-date-picker",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "An Angular directive to select dates using combo boxes",
55
"main": "source/ngComboDatePicker.js",
66
"scripts": {

source/ngComboDatePicker.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* ngComboDatePicker v1.3.0
2+
* ngComboDatePicker v1.3.1
33
* http://github.com/jfmdev/ngComboDatePicker
44
* «Copyright 2015 Jose F. Maldonado»
55
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
@@ -49,6 +49,11 @@ angular.module("ngComboDatePicker", [])
4949
return res;
5050
};
5151

52+
// Function to parse an string returning either a number or 'null' (instead of NaN).
53+
function parseIntStrict(num) {
54+
return (num !== null && num !== '' && parseInt(num) != NaN)? parseInt(num) : null;
55+
};
56+
5257
// Function to parse a JSON object.
5358
function parseJsonPlus(jsonObj) {
5459
var res = null;
@@ -153,10 +158,13 @@ angular.module("ngComboDatePicker", [])
153158
}
154159

155160
// Update list of months.
156-
$scope.updateMonthList = function() {
161+
$scope.updateMonthList = function(year) {
162+
// Parse parameter.
163+
year = parseIntStrict(year);
164+
157165
// Some months can not be choosed if the year matchs with the year of the minimum or maximum dates.
158-
var start = $scope.ngModel != null && $scope.ngModel.getFullYear() == $scope.minDate.getFullYear()? $scope.minDate.getMonth() : 0;
159-
var end = $scope.ngModel != null && $scope.ngModel.getFullYear() == $scope.maxDate.getFullYear()? $scope.maxDate.getMonth() : 11;
166+
var start = year !== null && year == $scope.minDate.getFullYear()? $scope.minDate.getMonth() : 0;
167+
var end = year !== null && year == $scope.maxDate.getFullYear()? $scope.maxDate.getMonth() : 11;
160168

161169
// Generate list.
162170
$scope.months = [];
@@ -167,16 +175,22 @@ angular.module("ngComboDatePicker", [])
167175
};
168176

169177
// Initialize list of days.
170-
$scope.updateDateList = function() {
178+
$scope.updateDateList = function(month, year) {
179+
// Parse parameters.
180+
month = parseIntStrict(month);
181+
year = parseIntStrict(year);
182+
171183
// Start date is 1, unless the selected month and year matchs the minimum date.
172184
var start = 1;
173-
if($scope.ngModel != null && $scope.ngModel.getMonth() == $scope.minDate.getMonth() && $scope.ngModel.getFullYear() == $scope.minDate.getFullYear()) {
185+
if(month !== null && month == $scope.minDate.getMonth() &&
186+
year !== null && year == $scope.minDate.getFullYear()) {
174187
start = $scope.minDate.getDate();
175188
}
176189

177190
// End date is 30 or 31 (28 or 29 in February), unless the selected month and year matchs the maximum date.
178-
var end = $scope.ngModel != null? maxDate($scope.ngModel.getMonth()+1, $scope.ngModel.getFullYear()) : maxDate(null, null);
179-
if($scope.ngModel != null && $scope.ngModel.getMonth() == $scope.maxDate.getMonth() && $scope.ngModel.getFullYear() == $scope.maxDate.getFullYear()) {
191+
var end = maxDate(month !== null? (month+1) : null, year);
192+
if(month !== null && month == $scope.maxDate.getMonth() &&
193+
year !== null && year == $scope.maxDate.getFullYear()) {
180194
end = $scope.maxDate.getDate();
181195
}
182196

@@ -223,8 +237,8 @@ angular.module("ngComboDatePicker", [])
223237
}
224238

225239
// Hide or show days and months according to the min and max dates.
226-
scope.updateMonthList();
227-
scope.updateDateList();
240+
scope.updateMonthList(res.year);
241+
scope.updateDateList(res.month, res.year);
228242
return res;
229243
});
230244

@@ -280,8 +294,8 @@ angular.module("ngComboDatePicker", [])
280294
}
281295

282296
// Hide or show days and months according to the min and max dates.
283-
scope.updateMonthList();
284-
scope.updateDateList();
297+
scope.updateMonthList(viewValue.year);
298+
scope.updateDateList(viewValue.month, viewValue.year);
285299

286300
return res;
287301
});

source/ngComboDatePicker.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)