From fab025bf6686398c4b1ccf30a8f6d32cc64f28a5 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Tue, 23 Apr 2019 17:27:34 +0200 Subject: [PATCH] V8: Don't use floats in the slider config as it only supports integers (#4821) --- .../PropertyEditors/SliderConfiguration.cs | 10 +++++----- .../views/propertyeditors/slider/slider.controller.js | 9 ++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs b/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs index 55ca199121..dc71c2a48f 100644 --- a/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs @@ -9,18 +9,18 @@ public bool EnableRange { get; set; } [ConfigurationField("initVal1", "Initial value", "number")] - public int InitialValue { get; set; } + public decimal InitialValue { get; set; } [ConfigurationField("initVal2", "Initial value 2", "number", Description = "Used when range is enabled")] - public int InitialValue2 { get; set; } + public decimal InitialValue2 { get; set; } [ConfigurationField("minVal", "Minimum value", "number")] - public int MinimumValue { get; set; } + public decimal MinimumValue { get; set; } [ConfigurationField("maxVal", "Maximum value", "number")] - public int MaximumValue { get; set; } + public decimal MaximumValue { get; set; } [ConfigurationField("step", "Step increments", "number")] - public int StepIncrements { get; set; } + public decimal StepIncrements { get; set; } } } diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/slider/slider.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/slider/slider.controller.js index 515eddf0a3..6c57cecdf1 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/slider/slider.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/slider/slider.controller.js @@ -38,7 +38,10 @@ const tooltips = $scope.model.config.enableRange ? [true, true] : [true]; const min = $scope.model.config.minVal ? [$scope.model.config.minVal] : [$scope.model.config.minVal]; const max = $scope.model.config.maxVal ? [$scope.model.config.maxVal] : [$scope.model.config.maxVal]; - + // don't render values with decimal places if the step increment in a whole number + var stepDecimalPlaces = $scope.model.config.step % 1 == 0 + ? 0 + : _.last($scope.model.config.step.toString().replace(",", ".").split(".")).length; // setup default $scope.sliderOptions = { "start": start, @@ -46,10 +49,10 @@ "tooltips": tooltips, "format": { to: function (value) { - return Math.round(value); + return value.toFixed(stepDecimalPlaces); }, from: function (value) { - return Math.round(value); + return value; } }, "range": {