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

Conversation

deeg
Copy link
Contributor

@deeg deeg commented Jan 11, 2016

Closes #5085

This stack says you should use Number when you want to make sure the entire string is a number.

Plunker showing fix.

@@ -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);
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.

@wesleycho
Copy link
Contributor

Linking a thorough list of different number parsers for reference.

IMO the unary operator is the best choice given it behaves identically to the Number constructor and cannot be overridden by the user.

@wesleycho wesleycho added this to the 1.0.1 milestone Jan 11, 2016
@deeg
Copy link
Contributor Author

deeg commented Jan 11, 2016

Sounds good, will change to that method.

@deeg
Copy link
Contributor Author

deeg commented Jan 11, 2016

@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);
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.

@deeg
Copy link
Contributor Author

deeg commented Jan 11, 2016

Alright, third times a charm!

@wesleycho wesleycho closed this in 9e9c6cf Jan 11, 2016
@deeg deeg deleted the fix-timepicker-letters branch April 12, 2016 13:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timepicker Bug:minute accepts alphabetic character and doesnt show validation error
2 participants