This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(input): format as string before running minlength/maxlength formatters #9277
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -608,6 +608,7 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { | |||
if (attr.ngMinlength) { | |||
var minlength = int(attr.ngMinlength); | |||
var minLengthValidator = function(value) { | |||
if (typeof value !== 'string' && !ctrl.$isEmpty(value)) value = value.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to just add a general formatter that always runs first for text input types and converts the value to a string... But unfortunately this is hard because formatters are run in reverse order, and the most common behaviour is to push a validator to the end. Maybe that's what we want, though (see 1eda183)
…rols Backported from 1eda183 NgModel will format all scope-based values to string when setting the viewValue for the associated input element. The formatting, however, only applies to input elements that contain a text, email, url or blank input type. In the event of a null or undefined scope or model value, the viewValue will be set to null or undefined instead of being converted to an empty string. Closes angular#5936
I rewrote this in a way which basically backports one commit matsko wrote, I think this is a better solution. Can be seen working in http://plnkr.co/edit/9nstD9vU8HRC8vUS8oOQ?p=preview |
@jeffbcross could you take a look? |
yep |
LGTM, one comment about adding more thorough expectations. |
sgtm |
caitp
added a commit
that referenced
this pull request
Sep 25, 2014
…rols Backported from 1eda183 NgModel will format all scope-based values to string when setting the viewValue for the associated input element. The formatting, however, only applies to input elements that contain a text, email, url or blank input type. In the event of a null or undefined scope or model value, the viewValue will be set to null or undefined instead of being converted to an empty string. Closes #5936 Closes #9277
Closed by 1b8b41a |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, minlength/maxlength would not work correctly when dealing with
non-string model values.
A better fix for this has already been implemented in 1.3, but unfortunately
implementing that fix in 1.2 is a bit harder as it requires a number of
commits to be backported in order to solve the problem correctly.
Closes #5936