-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Handle default or "no value supplied" case for the ng-maxlength directive #9874
Conversation
If one adds ng-maxlength="" to an input field, the default value of 0 for max length is used which results in an incorrect error being added to the input field. This fix checks for a value of 0 for the maxlength. If one uses this directive and purposefully supplies a value of 0 for the directive, that would make absolutely no sense in any scenario I can think of. By using this as the 'default' value (or the value used if a blank value is passed for this directive), and checking for that value and returning a result of 'valid' if that value is supplied, corrects this issue. This is not a problem for the ng-minlength directive as having a default value of 0 for the minimum length is actually a 'no-op' as you can't have a length less than 0.
I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS. Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match. If you signed the CLA as a corporation, please let us know the company's name. Thanks a bunch! PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR. |
Not sure about this; |
For what it's worth, it looks like a programming error to be too :) |
This sounds similar to #9995 - I can see that people could use an empty attribute to dynamically switch to the "unlimited" length. |
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
I think we should close this one in favour of #9998 which has tests, is more generic, doesn't break the build etc. |
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
Previously, setting the maxlength to a negative number, would make all input values invalid (since their length should be less than maxlength, which is impossible). This commit changes the behaviour of maxlength/ngMaxlength, effectively disabling the maxlength validation (always returning true) when maxlength is set to a negative number. This is more inline to how the HTML5 `maxlength` attribute works (both in browsers and according to the spec: http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength). Related to angular#9874 Closes angular#9995
…eger This makes the behaviour of maxlength/ngMaxlength more inline with the spec. Closes angular#9874
If one adds ng-maxlength="" to an input field, the default value of 0 for max length is used which results in an incorrect error being added to the input field. This fix checks for a value of 0 for the maxlength. If one uses this directive and purposefully supplies a value of 0 for the directive, that would make absolutely no sense in any scenario I can think of. By using this as the 'default' value (or the value used if a blank value is passed for this directive), and checking for that value and returning a result of 'valid' if that value is supplied, corrects this issue. This is not a problem for the ng-minlength directive as having a default value of 0 for the minimum length is actually a 'no-op' as you can't have a length less than 0.