@@ -165,7 +165,7 @@ angular.module('ui.bootstrap.timepicker', [])
165
165
var hours = + $scope . hours ;
166
166
var valid = $scope . showMeridian ? hours > 0 && hours < 13 :
167
167
hours >= 0 && hours < 24 ;
168
- if ( ! valid ) {
168
+ if ( ! valid || $scope . hours === '' ) {
169
169
return undefined ;
170
170
}
171
171
@@ -182,7 +182,11 @@ angular.module('ui.bootstrap.timepicker', [])
182
182
183
183
function getMinutesFromTemplate ( ) {
184
184
var minutes = + $scope . minutes ;
185
- return minutes >= 0 && minutes < 60 ? minutes : undefined ;
185
+ var valid = minutes >= 0 && minutes < 60 ;
186
+ if ( ! valid || $scope . minutes === '' ) {
187
+ return undefined ;
188
+ }
189
+ return minutes ;
186
190
}
187
191
188
192
function getSecondsFromTemplate ( ) {
@@ -322,7 +326,9 @@ angular.module('ui.bootstrap.timepicker', [])
322
326
323
327
hoursInputEl . bind ( 'blur' , function ( e ) {
324
328
ngModelCtrl . $setTouched ( ) ;
325
- if ( $scope . hours === null || $scope . hours === '' ) {
329
+ if ( modelIsEmpty ( ) ) {
330
+ makeValid ( ) ;
331
+ } else if ( $scope . hours === null || $scope . hours === '' ) {
326
332
invalidate ( true ) ;
327
333
} else if ( ! $scope . invalidHours && $scope . hours < 10 ) {
328
334
$scope . $apply ( function ( ) {
@@ -352,7 +358,9 @@ angular.module('ui.bootstrap.timepicker', [])
352
358
353
359
minutesInputEl . bind ( 'blur' , function ( e ) {
354
360
ngModelCtrl . $setTouched ( ) ;
355
- if ( $scope . minutes === null ) {
361
+ if ( modelIsEmpty ( ) ) {
362
+ makeValid ( ) ;
363
+ } else if ( $scope . minutes === null ) {
356
364
invalidate ( undefined , true ) ;
357
365
} else if ( ! $scope . invalidMinutes && $scope . minutes < 10 ) {
358
366
$scope . $apply ( function ( ) {
@@ -375,7 +383,9 @@ angular.module('ui.bootstrap.timepicker', [])
375
383
} ;
376
384
377
385
secondsInputEl . bind ( 'blur' , function ( e ) {
378
- if ( ! $scope . invalidSeconds && $scope . seconds < 10 ) {
386
+ if ( modelIsEmpty ( ) ) {
387
+ makeValid ( ) ;
388
+ } else if ( ! $scope . invalidSeconds && $scope . seconds < 10 ) {
379
389
$scope . $apply ( function ( ) {
380
390
$scope . seconds = pad ( $scope . seconds ) ;
381
391
} ) ;
@@ -464,6 +474,12 @@ angular.module('ui.bootstrap.timepicker', [])
464
474
return newDate ;
465
475
}
466
476
477
+ function modelIsEmpty ( ) {
478
+ return ( $scope . hours === null || $scope . hours === '' ) &&
479
+ ( $scope . minutes === null || $scope . minutes === '' ) &&
480
+ ( ! $scope . showSeconds || $scope . showSeconds && ( $scope . seconds === null || $scope . seconds === '' ) ) ;
481
+ }
482
+
467
483
$scope . showSpinners = angular . isDefined ( $attrs . showSpinners ) ?
468
484
$scope . $parent . $eval ( $attrs . showSpinners ) : timepickerConfig . showSpinners ;
469
485
0 commit comments