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

Add support for the input type=range #5892

Closed
andybak opened this issue Jan 20, 2014 · 59 comments · Fixed by #14870
Closed

Add support for the input type=range #5892

andybak opened this issue Jan 20, 2014 · 59 comments · Fixed by #14870

Comments

@andybak
Copy link

andybak commented Jan 20, 2014

Originally filed here: #1189

(This was incorrectly closed and despite requests to reopen, has remained closed so I'm reposting as a new ticket. For future reference, closing old tickets due to lack of activity is probably not a good idea.)

With multiple inputs to the same model doesn't play ball. It works as an input but updating it to a value set from another input always fails. Even if the source is also constrained as numeric (type="range" in chrome). This is due to the model being stored as a string.

Demo: http://jsfiddle.net/TXazw/5/Edit
Edit any input except the number and everything updates except the number input. Edit the number input and everything works fine.

A workaround is included. Uncomment parseFloat line and all inputs work correctly.

Should values not be automatically parsed when applied to a number type input? At the very least type="range" should be outputting a number rather than a string.

Discussed in the group:
https://groups.google.com/forum/?fromgroups#!topic/angular/Ecjx2fo8Qvk

@mlegenhausen
Copy link

+1

6 similar comments
@ludoblues
Copy link

+1

@adamnbowen
Copy link
Contributor

+1

@kazekagegaara
Copy link

+1

@ashclarke
Copy link

+1

@marcelbuesing
Copy link

+1

@vchirkov
Copy link

+1

@lgarron
Copy link

lgarron commented Mar 6, 2014

Indeed. It sounds petty, and it's probably easy to learn how to write a directive to fix this by passing through parseFloat(), but it's kind of annoying that a binding for input[type=range] is a string instead of a number.
Even if Javascript sometimes uses strings where something else would be suited better, this breaks the principle of least surprise, and has already caused me to create bugs.

Most use cases of input ranges will expect/need a number, and it's not terribly inefficient to support that.

@mismith
Copy link

mismith commented Mar 7, 2014

+1

@c9s
Copy link

c9s commented Mar 9, 2014

+1..

It should have something like ns-type="integer" or ns-type="float"

@lcerveau
Copy link

+1

1 similar comment
@mlison
Copy link

mlison commented Mar 26, 2014

+1

@btford btford added this to the Backlog milestone Mar 27, 2014
@etamasdan
Copy link

+1

2 similar comments
@Bretto
Copy link

Bretto commented Apr 3, 2014

+1

@baleboy
Copy link

baleboy commented May 6, 2014

+1

TylerEich pushed a commit to TylerEich/angular.js that referenced this issue May 6, 2014
Bind model of <input type="range"> to number (like <input type="number">) rather than string. Range inputs represent numerical values; therefore, a numerical binding makes more sense than a string binding.

Closes angular#1189, angular#5892
@marcalj
Copy link

marcalj commented Jun 26, 2014

+1

1 similar comment
@kunalnavhate
Copy link

+1

@ezaelbello
Copy link

+1

2 similar comments
@brunopaz
Copy link

brunopaz commented Aug 4, 2014

+1

@n1c
Copy link

n1c commented Aug 13, 2014

+1

@seriema
Copy link

seriema commented Jul 13, 2015

People have been writing +1 for 1.5 years. Can someone on the angular team comment?

@gkalpak
Copy link
Member

gkalpak commented Jul 13, 2015

(You mean like add a +1 themselves ? 😛)

@gkalpak
Copy link
Member

gkalpak commented Jul 13, 2015

This issue has the PRs plz label, which means that it would be a welcome addition and easy enough for a non-core member/external contributor to impelement.
It also has the Lots of comments label, which indicates that it is under the team's radar.

So, there's not much more to comment about it I guess (for the time being at least). If they haven't taken care of it yet, it's probably because they have been attending to other issues (bug fixes, perf improvements, features, chores) that were higher in priority (for whatever reason).

Patience poor issue...your turn will come...(unless, you know, it doesn't)...

(Not speaking on behalf of the team or anything...)

@TylerEich
Copy link
Contributor

@seriema #9715 is a PR for this issue. It's currently marked 1.5-candidate, so it may be resolved in v1.5

@rcollette
Copy link

+1

7 similar comments
@MrFranke
Copy link

MrFranke commented Oct 5, 2015

+1

@maxprof
Copy link

maxprof commented Oct 7, 2015

+1

@kunalnavhate
Copy link

+1

@michael-wirth
Copy link

+1

@ivorafael
Copy link

+1

@Tyutyesz
Copy link

Tyutyesz commented Dec 9, 2015

+1

@westonganger
Copy link

+1

@FLHerne
Copy link

FLHerne commented Feb 3, 2016

+1.

Just traced a weird-looking bug to this - in a language where ("7" + 3) * 10 is 730, having obviously-numeric values be strings is just asking for sensible-looking code to produce insane values.

@tayloj
Copy link

tayloj commented Feb 17, 2016

+1

1 similar comment
@ohcrider
Copy link

+1

@Narretz Narretz modified the milestones: 1.5.x, Backlog Jun 15, 2016
@dennybiasiolli
Copy link

+1

Narretz pushed a commit to Narretz/angular.js that referenced this issue Jul 5, 2016
the input[type=range] behavior is the same of an input[type=number]
with min=0, max=100 and step=1 as defaults

Closes angular#5892
Closes angular#9715
Narretz pushed a commit to Narretz/angular.js that referenced this issue Jul 5, 2016
the input[type=range] behavior is the same of an input[type=number]
with min=0, max=100 and step=1 as defaults

Closes angular#5892
Closes angular#9715
Narretz pushed a commit to Narretz/angular.js that referenced this issue Jul 29, 2016
Thanks to @cironunes for the initial implementation in angular#9715

Adds support for binding to input[range] with the following behavior / features:

- Like input[number], it requires the model to be a Number, and will set the model to a Number
- it supports setting the min/max values via the min/max and ngMin/ngMax attributes
- it follows the browser behavior of never allowing an invalid value. That means, when the browser
converts an invalid value (empty: null, undefined, false ..., out of bounds: greater than max, less than min)
to a valid value, the input will in turn set the model to this new valid value via $setViewValue.
-- this means a range input will never be required and never have a non-Number model value, once the
ngModel directive is initialized.
-- this behavior is supported when the model changes and when the min/max attributes change in a way
that prompts the browser to update the input value.
-- ngMin / ngMax do not prompt the browser to update the values, as they don't set the attribute values.
Instead, they will set the min / max errors when appropriate
- browsers that do not support input[range] (IE9) handle the input like a number input (with validation etc.)

Closes angular#5892
Closes angular#9715
Close angular#14870
Narretz added a commit to Narretz/angular.js that referenced this issue Jul 29, 2016
Thanks to @cironunes for the initial implementation in angular#9715

Adds support for binding to input[range] with the following behavior / features:

- Like input[number], it requires the model to be a Number, and will set the model to a Number
- it supports setting the min/max values via the min/max and ngMin/ngMax attributes
- it follows the browser behavior of never allowing an invalid value. That means, when the browser
converts an invalid value (empty: null, undefined, false ..., out of bounds: greater than max, less than min)
to a valid value, the input will in turn set the model to this new valid value via $setViewValue.
-- this means a range input will never be required and never have a non-Number model value, once the
ngModel directive is initialized.
-- this behavior is supported when the model changes and when the min/max attributes change in a way
that prompts the browser to update the input value.
-- ngMin / ngMax do not prompt the browser to update the values, as they don't set the attribute values.
Instead, they will set the min / max errors when appropriate
- browsers that do not support input[range] (IE9) handle the input like a number input (with validation etc.)

Closes angular#5892
Closes angular#9715
Close angular#14870
Narretz added a commit that referenced this issue Jul 29, 2016
Thanks to @cironunes for the initial implementation in #9715

Adds support for binding to input[range] with the following behavior / features:

- Like input[number], it requires the model to be a Number, and will set the model to a Number
- it supports setting the min/max values via the min/max and ngMin/ngMax attributes
- it follows the browser behavior of never allowing an invalid value. That means, when the browser
converts an invalid value (empty: null, undefined, false ..., out of bounds: greater than max, less than min)
to a valid value, the input will in turn set the model to this new valid value via $setViewValue.
-- this means a range input will never be required and never have a non-Number model value, once the
ngModel directive is initialized.
-- this behavior is supported when the model changes and when the min/max attributes change in a way
that prompts the browser to update the input value.
-- ngMin / ngMax do not prompt the browser to update the values, as they don't set the attribute values.
Instead, they will set the min / max errors when appropriate
- browsers that do not support input[range] (IE9) handle the input like a number input (with validation etc.)

Closes #5892
Closes #9715
Close #14870
Narretz added a commit that referenced this issue Jul 29, 2016
Thanks to @cironunes for the initial implementation in #9715

Adds support for binding to input[range] with the following behavior / features:

- Like input[number], it requires the model to be a Number, and will set the model to a Number
- it supports setting the min/max values via the min/max and ngMin/ngMax attributes
- it follows the browser behavior of never allowing an invalid value. That means, when the browser
converts an invalid value (empty: null, undefined, false ..., out of bounds: greater than max, less than min)
to a valid value, the input will in turn set the model to this new valid value via $setViewValue.
-- this means a range input will never be required and never have a non-Number model value, once the
ngModel directive is initialized.
-- this behavior is supported when the model changes and when the min/max attributes change in a way
that prompts the browser to update the input value.
-- ngMin / ngMax do not prompt the browser to update the values, as they don't set the attribute values.
Instead, they will set the min / max errors when appropriate
- browsers that do not support input[range] (IE9) handle the input like a number input (with validation etc.)

Closes #5892
Closes #9715
Close #14870
@sbaechler
Copy link

To summarize:
The bug has been fixed in version 1.5.9. But for it to work you have to add the attribute ng-input-range to the input[type=range] element. This is not necessary for Angular.js 1.6.

https://code.angularjs.org/1.5.9/docs/api/ng/input/input%5Brange%5D

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.