1
1
/*
2
- * ngComboDatePicker v1.3.0
2
+ * ngComboDatePicker v1.3.1
3
3
* http://github.com/jfmdev/ngComboDatePicker
4
4
* «Copyright 2015 Jose F. Maldonado»
5
5
* 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", [])
49
49
return res ;
50
50
} ;
51
51
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
+
52
57
// Function to parse a JSON object.
53
58
function parseJsonPlus ( jsonObj ) {
54
59
var res = null ;
@@ -153,10 +158,13 @@ angular.module("ngComboDatePicker", [])
153
158
}
154
159
155
160
// Update list of months.
156
- $scope . updateMonthList = function ( ) {
161
+ $scope . updateMonthList = function ( year ) {
162
+ // Parse parameter.
163
+ year = parseIntStrict ( year ) ;
164
+
157
165
// 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 ;
160
168
161
169
// Generate list.
162
170
$scope . months = [ ] ;
@@ -167,16 +175,22 @@ angular.module("ngComboDatePicker", [])
167
175
} ;
168
176
169
177
// 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
+
171
183
// Start date is 1, unless the selected month and year matchs the minimum date.
172
184
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 ( ) ) {
174
187
start = $scope . minDate . getDate ( ) ;
175
188
}
176
189
177
190
// 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 ( ) ) {
180
194
end = $scope . maxDate . getDate ( ) ;
181
195
}
182
196
@@ -223,8 +237,8 @@ angular.module("ngComboDatePicker", [])
223
237
}
224
238
225
239
// 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 ) ;
228
242
return res ;
229
243
} ) ;
230
244
@@ -280,8 +294,8 @@ angular.module("ngComboDatePicker", [])
280
294
}
281
295
282
296
// 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 ) ;
285
299
286
300
return res ;
287
301
} ) ;
0 commit comments