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

Handle default or "no value supplied" case for the ng-maxlength directive #9874

Closed
wants to merge 1 commit into from

Conversation

pavlovich
Copy link

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.

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.
@mary-poppins
Copy link

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.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@Narretz
Copy link
Contributor

Narretz commented Nov 2, 2014

Not sure about this; ng-maxlength without a value seems more like a programming error to me.

@gkalpak
Copy link
Member

gkalpak commented Nov 2, 2014

For what it's worth, it looks like a programming error to be too :)

@pkozlowski-opensource
Copy link
Member

This sounds similar to #9995 - I can see that people could use an empty attribute to dynamically switch to the "unlimited" length.

gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 11, 2014
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
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 11, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 11, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 11, 2014
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
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 11, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 11, 2014
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
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 11, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 11, 2014
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
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 11, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
@pkozlowski-opensource
Copy link
Member

I think we should close this one in favour of #9998 which has tests, is more generic, doesn't break the build etc.

gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 11, 2014
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
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 11, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 12, 2014
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
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 12, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 13, 2014
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
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 13, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 14, 2014
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
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 14, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 18, 2014
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
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 18, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 19, 2014
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
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 19, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 21, 2014
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
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 21, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
ajohnston256 pushed a commit to ajohnston256/angular.js that referenced this pull request Nov 22, 2014
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
ajohnston256 pushed a commit to ajohnston256/angular.js that referenced this pull request Nov 22, 2014
…eger

This makes the behaviour of maxlength/ngMaxlength more inline with the
spec.

Closes angular#9874
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants