Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

fix(timepicker): Don't allow mixture of numbers and letters. #5201

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = parseInt(+value, 10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think +value would be better if parseInt is not sufficient to ward off this issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I meant just changing it all to hourStep = +value and all the rest accordingly. No need to run parseInt after +, it's already a number at that stage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh, duh, will change.

});
}

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

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 = parseInt(+value, 10);
});
}

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 = parseInt(+$scope.hours, 10);
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 = parseInt(+$scope.minutes, 10);
return minutes >= 0 && minutes < 60 ? minutes : undefined;
}

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

Expand Down