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

fix(input): format as string before running minlength/maxlength formatters #9277

Closed
wants to merge 1 commit into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Sep 25, 2014

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

@@ -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();
Copy link
Contributor Author

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
@caitp
Copy link
Contributor Author

caitp commented Sep 25, 2014

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

@caitp
Copy link
Contributor Author

caitp commented Sep 25, 2014

@jeffbcross could you take a look?

@jeffbcross
Copy link
Contributor

yep

@jeffbcross
Copy link
Contributor

LGTM, one comment about adding more thorough expectations.

@caitp
Copy link
Contributor Author

caitp commented Sep 25, 2014

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
@caitp
Copy link
Contributor Author

caitp commented Sep 25, 2014

Closed by 1b8b41a

@caitp caitp closed this Sep 25, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants