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

Fix input range init #14996

Merged
merged 4 commits into from
Aug 12, 2016
Merged

Fix input range init #14996

merged 4 commits into from
Aug 12, 2016

Conversation

Narretz
Copy link
Contributor

@Narretz Narretz commented Aug 6, 2016

Please check if the PR fulfills these requirements

Other information:

This PR fixes 1 bigger and 2 smaller issues:

  • correctly initialize with interpolated min / max values

The interpolation directive only sets the actual element attribute value after
a digest passed. That means previously the min/max values on input range were
not set when the first $render happened, so the browser would not adjust
the input value according to min/max. This meant the range input and model would
not be initialzed as expected.

With this change, input range will set the actual element attribute value during its own
linking phase, as it is already available on the attrs argument passed to the link fn.

Fixes #14982

  • correctly sets the range value when min > max. Chrome and IE don't set this correctly in all cases.
  • removes interpolation from an ng-maxlength attribute in a test (interpolation in an attribute that expects an expression is discouraged)

@@ -1647,7 +1647,8 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
// IE11 doesn't set the el val correctly if the maxVal is greater than the element value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed this comment should say "less than" (instead of "greater than"), right?

@Narretz
Copy link
Contributor Author

Narretz commented Aug 9, 2016

@gkalpak Travis finally green, you may review this again :>


// This initalizes the min/max value, so that non-support browsers validate with the correct
// values during the initial $render
changeFn(initialAttrValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialAttrValue will be undefined for ngMin/ngMax. Is this intended?

It is not clear why this function would do different things for ngXyz vs xyz attributes. If this is intended, you could add a short comment explaining what is going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point we really only need to set the element attribute if we have min / max and the browser supports range. I've removed the call to changeFn as its use isn't tested currently.
The actual issue is that all validators that are based on observation if interpolation or ngX attributes only set their values after a digest. That means when the input renders these validators' valuea aren't defined. When the observers fire we will validate again with the correct values but this causes the model to be unset if the value is invalid. Imo this should still count as initialization so that shouldn't happen. The other thing is that we validate too often (once for every observer).
I'll open an issue for part 1 of this.

@gkalpak
Copy link
Member

gkalpak commented Aug 12, 2016

LGTM

…alues

The interpolation directive only sets the actual element attribute value after
a digest passed. That means previously, the min/max values on input range were
not set when the first $render happened, so the browser would not adjust
the input value according to min/max. This meant the range input and model would
not be initialzed as expected.

With this change, input range will set the actual element attribute value during its own
linking phase, as it is already available on the attrs argument passed to the link fn.

Fixes angular#14982
Since ng prefixed attributes do not set their corresponding element attribute, the range input would always have min = 0,
and max = 100 (in supported browsers), regardless of the value
in ngMin/ngMax. This is confusing and not very useful, so
it's better to not support them at all.
@Narretz Narretz force-pushed the fix-input-range-init branch from 1dfc7cb to 250801c Compare August 12, 2016 17:21
@Narretz Narretz merged commit a272a3c into angular:master Aug 12, 2016
@Narretz Narretz deleted the fix-input-range-init branch August 12, 2016 17:58
Narretz added a commit that referenced this pull request Aug 17, 2016
This commit fixes the handling of min/max, and removes support for ngMin/ngMax:

min/max:
Previously, interpolated min/max values on input range were not set when the first $render happens,
because the interpolation directive only sets the actual element attribute value after
a digest passes. That means that the browser would not adjust
the input value according to min/max and the range input and model would
not be initialzed as expected. 
With this change, input range will set the actual element attribute value during its own
linking phase, as it is already available on the attrs argument passed to the link fn.

ngMin/ngMax
Since ng prefixed attributes do not set their corresponding element attribute, the range input would always have min = 0, and max = 100 (in supported browsers), regardless of the value
in ngMin/ngMax. This is confusing and not very useful, so it's better to not support these attributes at all.

The commit also fixes a test which used an interpolation inside an attribute that expects an expression.

Fixes #14982 
PR (#14996)
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this pull request Sep 21, 2016
This commit fixes the handling of min/max, and removes support for ngMin/ngMax:

min/max:
Previously, interpolated min/max values on input range were not set when the first $render happens,
because the interpolation directive only sets the actual element attribute value after
a digest passes. That means that the browser would not adjust
the input value according to min/max and the range input and model would
not be initialzed as expected.
With this change, input range will set the actual element attribute value during its own
linking phase, as it is already available on the attrs argument passed to the link fn.

ngMin/ngMax
Since ng prefixed attributes do not set their corresponding element attribute, the range input would always have min = 0, and max = 100 (in supported browsers), regardless of the value
in ngMin/ngMax. This is confusing and not very useful, so it's better to not support these attributes at all.

The commit also fixes a test which used an interpolation inside an attribute that expects an expression.

Fixes angular#14982
PR (angular#14996)
 (reverted from commit b78539b)
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
This commit fixes the handling of min/max, and removes support for ngMin/ngMax:

min/max:
Previously, interpolated min/max values on input range were not set when the first $render happens,
because the interpolation directive only sets the actual element attribute value after
a digest passes. That means that the browser would not adjust
the input value according to min/max and the range input and model would
not be initialzed as expected. 
With this change, input range will set the actual element attribute value during its own
linking phase, as it is already available on the attrs argument passed to the link fn.

ngMin/ngMax
Since ng prefixed attributes do not set their corresponding element attribute, the range input would always have min = 0, and max = 100 (in supported browsers), regardless of the value
in ngMin/ngMax. This is confusing and not very useful, so it's better to not support these attributes at all.

The commit also fixes a test which used an interpolation inside an attribute that expects an expression.

Fixes angular#14982 
PR (angular#14996)
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
This commit fixes the handling of min/max, and removes support for ngMin/ngMax:

min/max:
Previously, interpolated min/max values on input range were not set when the first $render happens,
because the interpolation directive only sets the actual element attribute value after
a digest passes. That means that the browser would not adjust
the input value according to min/max and the range input and model would
not be initialzed as expected.
With this change, input range will set the actual element attribute value during its own
linking phase, as it is already available on the attrs argument passed to the link fn.

ngMin/ngMax
Since ng prefixed attributes do not set their corresponding element attribute, the range input would always have min = 0, and max = 100 (in supported browsers), regardless of the value
in ngMin/ngMax. This is confusing and not very useful, so it's better to not support these attributes at all.

The commit also fixes a test which used an interpolation inside an attribute that expects an expression.

Fixes angular#14982
PR (angular#14996)
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
This commit fixes the handling of min/max, and removes support for ngMin/ngMax:

min/max:
Previously, interpolated min/max values on input range were not set when the first $render happens,
because the interpolation directive only sets the actual element attribute value after
a digest passes. That means that the browser would not adjust
the input value according to min/max and the range input and model would
not be initialzed as expected.
With this change, input range will set the actual element attribute value during its own
linking phase, as it is already available on the attrs argument passed to the link fn.

ngMin/ngMax
Since ng prefixed attributes do not set their corresponding element attribute, the range input would always have min = 0, and max = 100 (in supported browsers), regardless of the value
in ngMin/ngMax. This is confusing and not very useful, so it's better to not support these attributes at all.

The commit also fixes a test which used an interpolation inside an attribute that expects an expression.

Fixes angular#14982
PR (angular#14996)
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
This commit fixes the handling of min/max, and removes support for ngMin/ngMax:

min/max:
Previously, interpolated min/max values on input range were not set when the first $render happens,
because the interpolation directive only sets the actual element attribute value after
a digest passes. That means that the browser would not adjust
the input value according to min/max and the range input and model would
not be initialzed as expected. 
With this change, input range will set the actual element attribute value during its own
linking phase, as it is already available on the attrs argument passed to the link fn.

ngMin/ngMax
Since ng prefixed attributes do not set their corresponding element attribute, the range input would always have min = 0, and max = 100 (in supported browsers), regardless of the value
in ngMin/ngMax. This is confusing and not very useful, so it's better to not support these attributes at all.

The commit also fixes a test which used an interpolation inside an attribute that expects an expression.

Fixes angular#14982 
PR (angular#14996)
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
This commit fixes the handling of min/max, and removes support for ngMin/ngMax:

min/max:
Previously, interpolated min/max values on input range were not set when the first $render happens,
because the interpolation directive only sets the actual element attribute value after
a digest passes. That means that the browser would not adjust
the input value according to min/max and the range input and model would
not be initialzed as expected.
With this change, input range will set the actual element attribute value during its own
linking phase, as it is already available on the attrs argument passed to the link fn.

ngMin/ngMax
Since ng prefixed attributes do not set their corresponding element attribute, the range input would always have min = 0, and max = 100 (in supported browsers), regardless of the value
in ngMin/ngMax. This is confusing and not very useful, so it's better to not support these attributes at all.

The commit also fixes a test which used an interpolation inside an attribute that expects an expression.

Fixes angular#14982
PR (angular#14996)
petebacondarwin pushed a commit that referenced this pull request Nov 23, 2016
This commit fixes the handling of min/max, and removes support for ngMin/ngMax:

min/max:
Previously, interpolated min/max values on input range were not set when the first $render happens,
because the interpolation directive only sets the actual element attribute value after
a digest passes. That means that the browser would not adjust
the input value according to min/max and the range input and model would
not be initialzed as expected.
With this change, input range will set the actual element attribute value during its own
linking phase, as it is already available on the attrs argument passed to the link fn.

ngMin/ngMax
Since ng prefixed attributes do not set their corresponding element attribute, the range input would always have min = 0, and max = 100 (in supported browsers), regardless of the value
in ngMin/ngMax. This is confusing and not very useful, so it's better to not support these attributes at all.

The commit also fixes a test which used an interpolation inside an attribute that expects an expression.

Fixes #14982
PR (#14996)
petebacondarwin pushed a commit that referenced this pull request Nov 24, 2016
This commit fixes the handling of min/max, and removes support for ngMin/ngMax:

min/max:
Previously, interpolated min/max values on input range were not set when the first $render happens,
because the interpolation directive only sets the actual element attribute value after
a digest passes. That means that the browser would not adjust
the input value according to min/max and the range input and model would
not be initialzed as expected.
With this change, input range will set the actual element attribute value during its own
linking phase, as it is already available on the attrs argument passed to the link fn.

ngMin/ngMax
Since ng prefixed attributes do not set their corresponding element attribute, the range input would always have min = 0, and max = 100 (in supported browsers), regardless of the value
in ngMin/ngMax. This is confusing and not very useful, so it's better to not support these attributes at all.

The commit also fixes a test which used an interpolation inside an attribute that expects an expression.

Fixes #14982
PR (#14996)
@icorne
Copy link

icorne commented Nov 28, 2016

Will this fix be back-ported to older angular versions?

@petebacondarwin
Copy link
Contributor

@icorne - which versions did you have in mind? We have no plans to backport it further back than 1.5.x

@icorne
Copy link

icorne commented Nov 28, 2016

I'm having trouble figuring out where this was merged into. I'm working on 1.5.x, so that's what I'm interested in. I've tried upgrading from 1.5.5 to 1.5.9 but I still get the issue.

@petebacondarwin
Copy link
Contributor

Ahah! Right. OK, it didn't make it into 1.5.9, since that was primarily a security release. It will be in 1.5.10.

@gkalpak
Copy link
Member

gkalpak commented Nov 28, 2016

This is already included in 1.5.9 (2e7121b), but support for input[range] is opt-in on 1.5.x in order to avoid a breaking change (see 07b8761 and the docs).

@petebacondarwin
Copy link
Contributor

Oops! I am so confused with all the rebasing we did last week that I forgot that we actually did put this in 1.5.9 :-) Thanks @gkalpak

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.

Input range doesn't respect interpolated min / max on initialization
5 participants