Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

step attribute doesn't trigger validity classes #10597

Closed
Mouvedia opened this issue Dec 29, 2014 · 14 comments
Closed

step attribute doesn't trigger validity classes #10597

Mouvedia opened this issue Dec 29, 2014 · 14 comments

Comments

@Mouvedia
Copy link

When you are using step="1" a float value enables validity.stepMismatch. This is not reflected by the ng classes on the input.
e.g.

<input ng-model="example" type="number" step="1" />

steps to reproduce:

  1. enter a float value
  2. check validity.stepMismatch of the input (true)
  3. check lack of ng-invalid class on the input

Affected version: 1.3.5

@pkozlowski-opensource
Copy link
Member

@Mouvedia it is next to impossible to assist you based on the info provided (or rather - lack of info...). Please provide a minimal, runnable reproduce scenario using http://plnkr.co/ or similar as per contribution guidelines

@Mouvedia
Copy link
Author

Ill update with more info. But it's pretty descriptive already.

@pkozlowski-opensource
Copy link
Member

But it's pretty descriptive already.

Yeh, might be for someone that sits in front of the code that exhibits the issue, but is far from being obvious for people not having exactly the same context as you have. For example, how can we guess what is the AngularJS version you are using?

@pkozlowski-opensource
Copy link
Member

Anyway, provide a live reproduce scenario using plunker and you will have a response in no time

@Mouvedia
Copy link
Author

@pkozlowski-opensource Seems no one will touch this for months now that you have put it in the "Purgatory" so Ill just use a custom validator to compensate for this obvious omission.

@pkozlowski-opensource
Copy link
Member

@Mouvedia we put things in the purgatory milestone by default where there is no enough info to confirm / reproduce the issue. It happens quite often, unfortunately, that people don't provide adequate info and don't come back to us after we request more info - we need a way of tracking those issues.

Now, if you want to speed up this issue resolution you can do one of those (which will be needed to fix the issue anyway):

  • send a pull request with a fix
  • check if the issue is still present in the latest version of AngularJS (once again, a plunker would avoid those back-and-forth)

You are welcomed to do any work-around on your side but if you want to see things improving on the core it would be great if you could send us a PR with a fix if you've investigated the issue already and qualified it as omission.

@Mouvedia
Copy link
Author

I can't imagine how much more strict you must be concerning PRs. So Ill just post the fix that Ill come up with when I am done.

@caitp
Copy link
Contributor

caitp commented Dec 29, 2014

Pawel, number and range inputs use the step attribute to rewrite inputs to be multiples of a given step value. We don't have handled for this for the number our range types, and when native validators are used, we ignore the step mismatch flags. That is the bug they're talking about

@Mouvedia
Copy link
Author

Floating point math is sure annoying in javascript. I suppose that's why you left it out.
For now Ill just check validity.stepMismatch and won't provide a fallback for browser that don't support the Constraint API.

@caitp
Copy link
Contributor

caitp commented Dec 29, 2014

I don't think it would be problematic to support, actually. It's just that nobody had asked for it

@caitp
Copy link
Contributor

caitp commented Dec 29, 2014

Apologies for words that don't make sense, blame mobile :<

@Mouvedia
Copy link
Author

If you have already done accurate division by floats then yeah the fallback should be a piece of cake. Just remember that you could have invalid values as well.

e.g. step="word"

@Mouvedia
Copy link
Author

.directive("step", function() {
    return {
        restrict: "A",
        require: "ngModel",
        link: function(scope, element, attributes, ngModel) {
            ngModel.$validators.step = function() {
                return element[0].validity.stepMismatch === false;
            };
        }
    };
});

@jimmywarting
Copy link
Contributor

Should work on date month week datetime datetime-local time range number

Narretz added a commit to Narretz/angular.js that referenced this issue Aug 16, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes angular#10597
Narretz added a commit to Narretz/angular.js that referenced this issue Aug 17, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes angular#10597
Narretz added a commit that referenced this issue Aug 17, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes #10597
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Sep 21, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes angular#10597 (reverted from commit c0b42f0)
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes angular#10597
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes angular#10597
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes angular#10597
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes angular#10597
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes angular#10597
petebacondarwin pushed a commit that referenced this issue Nov 23, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes #10597
petebacondarwin pushed a commit that referenced this issue Nov 24, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes #10597
gkalpak pushed a commit that referenced this issue Nov 25, 2016
input[number] will now set the step error if the input value
(ngModel $viewValue) does not fit the step constraint set in the step / ngStep attribute.

Fixes #10597
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants