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] 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),