From e464cc05134b5d010911cfb89b1403ed0d9400fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Miko=C5=82ajczyk?= Date: Fri, 20 Feb 2015 14:54:22 +0100 Subject: [PATCH 1/2] gracefully handle deleting modelMax through input When modelMax is deleted, e.g. by a user pushing backspace when focused on an input field which has ng-model set to modelMin or modelMax, then modelMax is are set to 0 or modelMin. This fixes the issue that happens when trying to delete the last cipher from an input field - the value just resets to max. --- angular.rangeSlider.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/angular.rangeSlider.js b/angular.rangeSlider.js index 3f71549..f3d348e 100644 --- a/angular.rangeSlider.js +++ b/angular.rangeSlider.js @@ -368,7 +368,18 @@ if (scope.pinHandle !== 'max') { throwWarning('modelMax must be a number'); } - scope.modelMax = scope.max; + // scope.modelMax = scope.max; + + // if deleted with backspace in a type="number" input, the value is set to null + if (scope.modelMax === null) { + if (scope.modelMin) { + scope.modelMax = scope.modelMin + } else if (scope.min) { + scope.modelMax = scope.min; + } else { + scope.modelMax = 0; + } + } } var handle1pos = restrict(((scope.modelMin - scope.min) / range) * 100), From 9399ba2ee7f21b6f6055cac3c8eef2fd1a2cd5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Miko=C5=82ajczyk?= Date: Wed, 4 Mar 2015 13:27:37 +0100 Subject: [PATCH 2/2] handling modelMax deleted value only when unpinned --- angular.rangeSlider.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/angular.rangeSlider.js b/angular.rangeSlider.js index f3d348e..c52057a 100644 --- a/angular.rangeSlider.js +++ b/angular.rangeSlider.js @@ -365,19 +365,15 @@ } if (!isNumber(scope.modelMax)) { + scope.modelMax = scope.max; if (scope.pinHandle !== 'max') { throwWarning('modelMax must be a number'); - } - // scope.modelMax = scope.max; - - // if deleted with backspace in a type="number" input, the value is set to null - if (scope.modelMax === null) { if (scope.modelMin) { - scope.modelMax = scope.modelMin + scope.modelMax = scope.modelMin; } else if (scope.min) { - scope.modelMax = scope.min; + scope.modelMax = scope.min; } else { - scope.modelMax = 0; + scope.modelMax = 0; } } }