Skip to content

Commit

Permalink
fix(timepicker): Don't allow mixture of numbers and letters.
Browse files Browse the repository at this point in the history
  • Loading branch information
deeg committed Jan 11, 2016
1 parent aa010b0 commit d322192
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/timepicker/test/timepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,6 @@ describe('timepicker directive', function() {
expect(getModelState()).toEqual([14, 9, 25]);
});


it('updates seconds & pads on input change & pads on blur', function() {
var el = getSecondsInputEl();

Expand Down Expand Up @@ -1192,7 +1191,7 @@ describe('timepicker directive', function() {
it('clears model when input minutes is invalid & alerts the UI', function() {
var el = getMinutesInputEl();

changeInputValueTo(el, 'pizza');
changeInputValueTo(el, '8a');
expect($rootScope.time).toBe(null);
expect(el.parent().hasClass('has-error')).toBe(true);
expect(element.hasClass('ng-invalid-time')).toBe(true);
Expand All @@ -1204,7 +1203,6 @@ describe('timepicker directive', function() {
expect(element.hasClass('ng-invalid-time')).toBe(false);
});


it('clears model when input seconds is invalid & alerts the UI', function() {
var el = getSecondsInputEl();

Expand Down
12 changes: 6 additions & 6 deletions src/timepicker/timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ angular.module('ui.bootstrap.timepicker', [])
var hourStep = timepickerConfig.hourStep;
if ($attrs.hourStep) {
$scope.$parent.$watch($parse($attrs.hourStep), function(value) {
hourStep = parseInt(value, 10);
hourStep = Number(value);
});
}

var minuteStep = timepickerConfig.minuteStep;
if ($attrs.minuteStep) {
$scope.$parent.$watch($parse($attrs.minuteStep), function(value) {
minuteStep = parseInt(value, 10);
minuteStep = Number(value);
});
}

Expand Down Expand Up @@ -128,7 +128,7 @@ angular.module('ui.bootstrap.timepicker', [])
var secondStep = timepickerConfig.secondStep;
if ($attrs.secondStep) {
$scope.$parent.$watch($parse($attrs.secondStep), function(value) {
secondStep = parseInt(value, 10);
secondStep = Number(value);
});
}

Expand Down Expand Up @@ -160,7 +160,7 @@ angular.module('ui.bootstrap.timepicker', [])

// Get $scope.hours in 24H mode if valid
function getHoursFromTemplate() {
var hours = parseInt($scope.hours, 10);
var hours = Number($scope.hours);
var valid = $scope.showMeridian ? hours > 0 && hours < 13 :
hours >= 0 && hours < 24;
if (!valid) {
Expand All @@ -179,12 +179,12 @@ angular.module('ui.bootstrap.timepicker', [])
}

function getMinutesFromTemplate() {
var minutes = parseInt($scope.minutes, 10);
var minutes = Number($scope.minutes);
return minutes >= 0 && minutes < 60 ? minutes : undefined;
}

function getSecondsFromTemplate() {
var seconds = parseInt($scope.seconds, 10);
var seconds = Number($scope.seconds);
return seconds >= 0 && seconds < 60 ? seconds : undefined;
}

Expand Down

0 comments on commit d322192

Please sign in to comment.