Skip to content

Commit 3bab8ae

Browse files
committed
feat(input): add support to input[type=range]
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, angular#8241, angular#7370
1 parent 7cb01a8 commit 3bab8ae

File tree

2 files changed

+713
-0
lines changed

2 files changed

+713
-0
lines changed

src/ng/directive/input.js

+57
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,63 @@ var inputType = {
830830
*/
831831
'radio': radioInputType,
832832

833+
/**
834+
* @ngdoc input
835+
* @name input[range]
836+
*
837+
* @description
838+
* Native range input with number validation and transformation. Sets the `number` validation
839+
* to always have a valid number.
840+
*
841+
* @param {string} ngModel Assignable angular expression to data-bind to.
842+
* @param {string=} name Property name of the form under which the control is published.
843+
* @param {string=} min Sets the `min` validation error key if the value entered is less than `min`.
844+
* @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`.
845+
* @param {string=} ngPattern Sets `pattern` validation error key if the value does not match the
846+
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
847+
* patterns defined as scope expressions.
848+
* @param {string=} ngChange Angular expression to be executed when input changes due to user
849+
* interaction with the input element.
850+
*
851+
* @example
852+
<example name="range-input-directive" module="rangeExample">
853+
<file name="index.html">
854+
<script>
855+
angular.module('rangeExample', [])
856+
.controller('ExampleController', ['$scope', function($scope) {
857+
$scope.value = 50;
858+
}]);
859+
</script>
860+
<form name="myForm" ng-controller="ExampleController">
861+
Number: <input type="range" name="input" ng-model="value"
862+
min="0" max="100">
863+
<tt>value = {{value}}</tt><br/>
864+
<tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
865+
<tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
866+
<tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
867+
<tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
868+
</form>
869+
</file>
870+
<file name="protractor.js" type="protractor">
871+
var value = element(by.binding('value'));
872+
var valid = element(by.binding('myForm.input.$valid'));
873+
var input = element(by.model('value'));
874+
875+
it('should initialize to model', function() {
876+
expect(value.getText()).toContain('50');
877+
expect(valid.getText()).toContain('true');
878+
});
879+
880+
it('should respect the max', function() {
881+
input.clear();
882+
input.sendKeys('123');
883+
expect(value.getText()).toEqual('value = 100');
884+
expect(valid.getText()).toContain('true');
885+
});
886+
</file>
887+
</example>
888+
*/
889+
'range': numberInputType,
833890

834891
/**
835892
* @ngdoc input

0 commit comments

Comments
 (0)