Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit efcacbe

Browse files
author
Valentin Hervieu
committed
feat(enforceRange): Add an enforceRange options.
Set to true to round the `rzSliderModel` and `rzSliderHigh` to the slider range even when modified from outside the slider. When set to false, if the model values are modified from outside the slider, they are not rounded but they are still rendered properly on the slider. Closes angular-slider#208.
1 parent c5c07a5 commit efcacbe

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ The default options are:
172172
selectionBarColor: null,
173173
keyboardSupport: true,
174174
scale: 1,
175+
enforceRange: false,
175176
onStart: null,
176177
onChange: null,
177178
onEnd: null
@@ -235,6 +236,8 @@ $scope.slider = {
235236

236237
**scale** - _Number (defaults to 1)_: If you display the slider in an element that uses `transform: scale(0.5)`, set the `scale` value to 2 so that the slider is rendered properly and the events are handled correctly.
237238

239+
**enforceRange** - _Boolean (defaults to false)_: Set to true to round the `rzSliderModel` and `rzSliderHigh` to the slider range even when modified from outside the slider. When set to false, if the model values are modified from outside the slider, they are not rounded but they are still rendered properly on the slider.
240+
238241
**onStart** - _Function(sliderId)_: Function to be called when a slider update is started. If an id was set in the options, then it's passed to this callback.
239242

240243
**onChange** - _Function(sliderId)_: Function to be called when rz-slider-model or rz-slider-high change. If an id was set in the options, then it's passed to this callback.

dist/rzslider.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
selectionBarColor: null,
4848
keyboardSupport: true,
4949
scale: 1,
50+
enforceRange: false,
5051
onStart: null,
5152
onChange: null,
5253
onEnd: null
@@ -625,6 +626,12 @@
625626
else
626627
this.maxValue = this.options.ceil = this.range ? this.scope.rzSliderHigh : this.scope.rzSliderModel;
627628

629+
if (this.options.enforceRange) {
630+
this.scope.rzSliderModel = this.sanitizeValue(this.scope.rzSliderModel);
631+
if (this.range)
632+
this.scope.rzSliderHigh = this.sanitizeValue(this.scope.rzSliderHigh);
633+
}
634+
628635
this.valueRange = this.maxValue - this.minValue;
629636
},
630637

0 commit comments

Comments
 (0)