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

max validator of input element do not work as expected on some cases #10307

Closed
tobyee opened this issue Dec 3, 2014 · 2 comments
Closed

max validator of input element do not work as expected on some cases #10307

tobyee opened this issue Dec 3, 2014 · 2 comments

Comments

@tobyee
Copy link
Contributor

tobyee commented Dec 3, 2014

Demo Html, or view it on Plunker

<!DOCTYPE html>
<html lang="en">
<head>
    <title></title>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
    <script>
        angular.module("foo", []).controller("fooCtrl", function ($scope) {
            $scope.limit3 = 2;
        });
    </script>
    <style>
        input.ng-invalid {
            background-color: red;
        }
    </style>
</head>
<body ng-app="foo">
    <label>Form 1</label>
    <form action="/" method="post">
        <!--no controller-->
        <input type="number" ng-model="limit1" placeholder="limit" />
        <input type="number" max="{{limit1}}" ng-model="used1" placeholder="used" />
    </form>
    <br />
    <label>Form 2</label>
    <form action="/" method="post">
        <!--no controller, use ng-init directive-->
        <input type="number" ng-init="limit2=2" ng-model="limit2" placeholder="limit" />
        <input type="number" max="{{limit2}}" ng-model="used2" placeholder="used" />
    </form>
    <br />
    <label>Form 3</label>
    <form action="/" method="post" ng-controller="fooCtrl">
        <!--has controller-->
        <input type="number" ng-model="limit3" placeholder="limit" />
        <input type="number" max="{{limit3}}" ng-model="used3" placeholder="used" />
    </form>
</body>
</html>

Result:

rtx

The problem if that form 1 can not detect the max error.
This issue was found in both 1.2.x and 1.3.x.
I haven't test the other validators, such as min, max-length, may be there are some problem.

@gkalpak
Copy link
Member

gkalpak commented Dec 3, 2014

The problem seems to be at L1253 (if (attr.max || attr.ngMax) {), were we should be checking if attr.max/ngMax are defined (not truthy).

Interestingly enough, we are (almost) doing the right thing at L1179 for the date input (if (isDefined(attr.max) || attr.ngMax) {); at least for the max attribute.

@Narretz
Copy link
Contributor

Narretz commented Dec 4, 2014

Does one of you fancy sending a PR?

tobyee added a commit to tobyee/angular.js that referenced this issue Dec 4, 2014
tobyee added a commit to tobyee/angular.js that referenced this issue Dec 5, 2014
…ue is

- fix issue angular#10307
- change tests to corresponding changes
- also change tests for ngmax and ngmin (though they have no some issue)

Closes angular#10307
tobyee added a commit to tobyee/angular.js that referenced this issue Dec 6, 2014
…ue is

- fix issue angular#10307
- change tests to corresponding changes
- also change tests for ngmax and ngmin (though they have no some issue)

Closes angular#10307
Narretz pushed a commit that referenced this issue Feb 10, 2015
Also adds corresponding tests for ngMin / ngMax.

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

Successfully merging a pull request may close this issue.

3 participants