-
Notifications
You must be signed in to change notification settings - Fork 6.7k
fix(timepicker): Don't allow mixture of numbers and letters. #5201
Conversation
@@ -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); |
There was a problem hiding this comment.
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.
Linking a thorough list of different number parsers for reference. IMO the unary operator is the best choice given it behaves identically to the |
Sounds good, will change to that method. |
@wesleycho, should be all set. Updated plunker with new code. |
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh, duh, will change.
Alright, third times a charm! |
Closes #5085
This stack says you should use Number when you want to make sure the entire string is a number.
Plunker showing fix.