@@ -180,7 +180,11 @@ angular.module('ui.bootstrap.timepicker', [])
180
180
return ( seconds >= 0 && seconds < 60 ) ? seconds : undefined ;
181
181
}
182
182
183
- function pad ( value ) {
183
+ function pad ( value ) {
184
+ if ( value === null ) {
185
+ return '' ;
186
+ }
187
+
184
188
return ( angular . isDefined ( value ) && value . toString ( ) . length < 2 ) ? '0' + value : value . toString ( ) ;
185
189
}
186
190
@@ -209,7 +213,6 @@ angular.module('ui.bootstrap.timepicker', [])
209
213
$scope . $apply ( ( isScrollingUp ( e ) ) ? $scope . incrementSeconds ( ) : $scope . decrementSeconds ( ) ) ;
210
214
e . preventDefault ( ) ;
211
215
} ) ;
212
-
213
216
} ;
214
217
215
218
// Respond on up/down arrowkeys
@@ -281,6 +284,7 @@ angular.module('ui.bootstrap.timepicker', [])
281
284
282
285
if ( angular . isDefined ( hours ) && angular . isDefined ( minutes ) ) {
283
286
selected . setHours ( hours ) ;
287
+ selected . setMinutes ( minutes ) ;
284
288
if ( selected < min || selected > max ) {
285
289
invalidate ( true ) ;
286
290
} else {
@@ -292,7 +296,10 @@ angular.module('ui.bootstrap.timepicker', [])
292
296
} ;
293
297
294
298
hoursInputEl . bind ( 'blur' , function ( e ) {
295
- if ( ! $scope . invalidHours && $scope . hours < 10 ) {
299
+ ngModelCtrl . $setTouched ( ) ;
300
+ if ( $scope . hours === null || $scope . hours === '' ) {
301
+ invalidate ( true ) ;
302
+ } else if ( ! $scope . invalidHours && $scope . hours < 10 ) {
296
303
$scope . $apply ( function ( ) {
297
304
$scope . hours = pad ( $scope . hours ) ;
298
305
} ) ;
@@ -304,6 +311,7 @@ angular.module('ui.bootstrap.timepicker', [])
304
311
hours = getHoursFromTemplate ( ) ;
305
312
306
313
if ( angular . isDefined ( minutes ) && angular . isDefined ( hours ) ) {
314
+ selected . setHours ( hours ) ;
307
315
selected . setMinutes ( minutes ) ;
308
316
if ( selected < min || selected > max ) {
309
317
invalidate ( undefined , true ) ;
@@ -316,7 +324,10 @@ angular.module('ui.bootstrap.timepicker', [])
316
324
} ;
317
325
318
326
minutesInputEl . bind ( 'blur' , function ( e ) {
319
- if ( ! $scope . invalidMinutes && $scope . minutes < 10 ) {
327
+ ngModelCtrl . $setTouched ( ) ;
328
+ if ( $scope . minutes === null ) {
329
+ invalidate ( undefined , true ) ;
330
+ } else if ( ! $scope . invalidMinutes && $scope . minutes < 10 ) {
320
331
$scope . $apply ( function ( ) {
321
332
$scope . minutes = pad ( $scope . minutes ) ;
322
333
} ) ;
@@ -381,22 +392,31 @@ angular.module('ui.bootstrap.timepicker', [])
381
392
}
382
393
383
394
function updateTemplate ( keyboardChange ) {
384
- var hours = selected . getHours ( ) ,
385
- minutes = selected . getMinutes ( ) ,
386
- seconds = selected . getSeconds ( ) ;
395
+ if ( ngModelCtrl . $modelValue == null ) {
396
+ $scope . hours = null ;
397
+ $scope . minutes = null ;
398
+ $scope . seconds = null ;
399
+ $scope . meridian = meridians [ 0 ] ;
400
+ } else {
401
+ var hours = selected . getHours ( ) ,
402
+ minutes = selected . getMinutes ( ) ,
403
+ seconds = selected . getSeconds ( ) ;
387
404
388
- if ( $scope . showMeridian ) {
389
- hours = ( hours === 0 || hours === 12 ) ? 12 : hours % 12 ; // Convert 24 to 12 hour system
390
- }
405
+ if ( $scope . showMeridian ) {
406
+ hours = ( hours === 0 || hours === 12 ) ? 12 : hours % 12 ; // Convert 24 to 12 hour system
407
+ }
391
408
392
- $scope . hours = keyboardChange === 'h' ? hours : pad ( hours ) ;
393
- if ( keyboardChange !== 'm' ) {
394
- $scope . minutes = pad ( minutes ) ;
395
- }
396
- if ( keyboardChange !== 's' ) {
397
- $scope . seconds = pad ( seconds ) ;
409
+ $scope . hours = keyboardChange === 'h' ? hours : pad ( hours ) ;
410
+ if ( keyboardChange !== 'm' ) {
411
+ $scope . minutes = pad ( minutes ) ;
412
+ }
413
+ $scope . meridian = selected . getHours ( ) < 12 ? meridians [ 0 ] : meridians [ 1 ] ;
414
+
415
+ if ( keyboardChange !== 's' ) {
416
+ $scope . seconds = pad ( seconds ) ;
417
+ }
418
+ $scope . meridian = selected . getHours ( ) < 12 ? meridians [ 0 ] : meridians [ 1 ] ;
398
419
}
399
- $scope . meridian = selected . getHours ( ) < 12 ? meridians [ 0 ] : meridians [ 1 ] ;
400
420
}
401
421
402
422
function addSecondsToSelected ( seconds ) {
@@ -455,8 +475,15 @@ angular.module('ui.bootstrap.timepicker', [])
455
475
} ;
456
476
457
477
$scope . toggleMeridian = function ( ) {
478
+ var minutes = getMinutesFromTemplate ( ) ,
479
+ hours = getHoursFromTemplate ( ) ;
480
+
458
481
if ( ! $scope . noToggleMeridian ( ) ) {
459
- addSecondsToSelected ( 12 * 60 * ( selected . getHours ( ) < 12 ? 60 : - 60 ) ) ;
482
+ if ( angular . isDefined ( minutes ) && angular . isDefined ( hours ) ) {
483
+ addSecondsToSelected ( 12 * 60 * ( selected . getHours ( ) < 12 ? 60 : - 60 ) ) ;
484
+ } else {
485
+ $scope . meridian = $scope . meridian === meridians [ 0 ] ? meridians [ 1 ] : meridians [ 0 ] ;
486
+ }
460
487
}
461
488
} ;
462
489
} ] )
0 commit comments