We've run into a minor problem with the Kendo slider. When navigating to a new view, if that view has a slider (or multiple sliders) on it that are in an element that is not visible, the user can not change the value of the slider with the mouse. You can use the left/right arrows to change the value (and the events fire), but the slider won't move.
If you then navigate off of the view, and then back onto that same view, the slider then works. I've put a little demo together in the Dojo that illustrates what I'm talking about:
Any suggestions as to a workaround?

I have a need for a slider switch with text labels instead of numbers. Instead of 1,2,3 I need Small, Medium, Large. It does not appear that Kendo UI has a built in way to do this so here is the function I came up with:
/*
This helper is designed to allow you to substitute a datasource for values in a kendo slider to do things like:
"small", "medium", "large".
It includes 4 functions that should be used instead of the ones included with Kendo UI:
initializeKendoSlider(options);
getKendoSliderSelection(elementId);
resizeKendoSlider(elementId);
setKendoSliderValue(elementId, newValue);
*/
function initializeKendoSlider(options) {
/*
options = {
elementId: string - required,
dataSource: [{ label: string, value: any}],
value: any - the value prop of any dataSource item
orientation: string - defaults to "horizontal",
tickPlacement: string - defaults to "bottomRight",
change: custom change function. Available parameters are: selectedDataItem, e
};
Include this in your html to start:
<input id="mySlider" name="mySlider" type="text" />
NOTE: If a proper dataSource is not passed, the slider will build as a numeric Kendo Slider.
NOTE: The value returned by the .value() function is the index, not the actual value. You must use
the included getKendoSliderSelection and setKendoSliderValue functions.
NOTE: The change function will return the selected item as the second parameter which can be used in your custom change function.
NOTE: Kendo's built in max and min methods will not work properly when using a dataSource.
NOTE: Small steps are not supported.
*/
if (!options.elementId || typeof options.elementId !== "string") {
console.error("No Element ID Passed");
return false;
}
let elementId = options.elementId;
if (Array.isArray(options.dataSource)) {
// Destroy the existing slider
if ($(`#${elementId}`).data("kendoSlider")) {
$(`#${elementId}`).data("kendoSlider").destroy();
if ($(`#${elementId}`).closest(".custom-form-slider").length > 0) {
$(`#${elementId}`).closest(".custom-form-slider").replaceWith($(`#${elementId}`));
} else if ($(`#${elementId}`).closest(".k-slider").length > 0) {
$(`#${elementId}`).closest(".k-slider").replaceWith($(`#${elementId}`));
}
}
// Prep options for slider
let defaultValue = options.value ? options.dataSource.findIndex(x => x.value === options.value) : 0;
let tickPlacement = options.tickPlacement;
if (tickPlacement !== "topLeft" && tickPlacement !== "both") {
tickPlacement = "bottomRight";
}
options.tickPlacement = tickPlacement;
// Build the slider
let objectSlider = $(`#${elementId}`).kendoSlider({
showButtons: false,
dataSource: options.dataSource,
min: 0,
max: options.dataSource.length - 1,
orientation: options.orientation === "vertical" ? options.orientation : "horizontal",
tickPlacement: tickPlacement,
value: defaultValue,
largeStep: 1,
change: function (e) {
let selectedDataItem = getKendoSliderSelection(options.elementId);
if (typeof options.change === "function") {
options.change(selectedDataItem, e);
}
},
tooltip: {
enabled: false
}
}).data("kendoSlider");
// Changes the numbers to text labels
var sliderItems = $(`#${elementId}`).siblings(".k-slider-items");
$.each(options.dataSource, function (index, step) {
var item = sliderItems.find("li:eq(" + (index) + ")");
item.attr("title", step.label);
item.find("span").text(step.label);
});
// Fixes the alignment due to absulutely positioned labels
if (sliderItems.length > 0) {
if (options.orientation !== "vertical" && (tickPlacement === "bottomRight" || tickPlacement === "both")) {
let left = sliderItems.find("li:eq(0) span")[0].getBoundingClientRect().width;
let right = sliderItems.find(`li:eq(${options.dataSource.length - 1}) span`)[0].getBoundingClientRect().width;
$(`#${elementId}`).closest(".k-slider").wrap(`<div class="custom-form-slider" style="padding-left: ${left / 2}px; padding-right: ${right / 2}px; padding-bottom: 1.2em"></div>`);
} else if (options.orientation === "vertical" && (tickPlacement === "bottomRight" || tickPlacement === "both")) {
let maxLabelWidth = 0;
$.each(options.dataSource, function (index) {
var item = sliderItems.find("li:eq(" + (index) + ") span");
let thisWidth = item[0].getBoundingClientRect().width;
if (thisWidth > maxLabelWidth) {
maxLabelWidth = thisWidth;
}
});
$(`#${elementId}`).closest(".k-slider").wrap(`<div class="custom-form-slider" style="display: inline-block; padding-right: ${maxLabelWidth + 10}px; padding-bottom: 14px"></div>`);
} else if (options.orientation === "horizontal" && (tickPlacement === "topLeft")) {
let left = sliderItems.find("li:eq(0) span")[0].getBoundingClientRect().width;
let right = sliderItems.find(`li:eq(${options.dataSource.length - 1}) span`)[0].getBoundingClientRect().width;
$(`#${elementId}`).closest(".k-slider").wrap(`<div class="custom-form-slider" style="padding-left: ${left / 2}px; padding-right: ${right / 2}px; padding-top: 1.2em"></div>`);
} else if (options.orientation === "vertical" && (tickPlacement === "topLeft")) {
let maxLabelWidth = 0;
$.each(options.dataSource, function (index) {
var item = sliderItems.find("li:eq(" + (index) + ") span");
let thisWidth = item[0].getBoundingClientRect().width;
if (thisWidth > maxLabelWidth) {
maxLabelWidth = thisWidth;
}
});
$(`#${elementId}`).closest(".k-slider").wrap(`<div class="custom-form-slider" style="display: inline-block; padding-left: ${maxLabelWidth + 10}px; padding-bottom: 14px"></div>`);
} else {
$(`#${elementId}`).closest(".k-slider").wrap('<div class="custom-form-slider"></div>');
}
} else {
$(`#${elementId}`).closest(".k-slider").wrap('<div class="custom-form-slider"></div>');
}
// Add event listener
const debouncedResize = debounce(() => resizeKendoSlider(elementId), 300);
window.addEventListener("resize", debouncedResize);
return objectSlider;
} else if (options.options) {
// NOTE: This will use the standard KendoSlider initialization.
let objectSlider = $(`#${options.elementId}`).kendoSlider(options.options).data("kendoSlider");
return objectSlider;
} else {
console.error("No dataSource or options passed to initializeKendoSlider. Must have at least one");
return false;
}
}
function resizeKendoSlider(elementId) {
let thisSlider = $(`#${elementId}`).data("kendoSlider");
let options = thisSlider.options;
let tickPlacement = options.tickPlacement;
// Trigger the kendo slider resize to get any missing ticks
thisSlider.resize();
// Changes the numbers to text labels so we can calculate the size
let sliderItems = $(`#${elementId}`).siblings(".k-slider-items");
$.each(options.dataSource, function (index, step) {
let item = sliderItems.find("li:eq(" + (index) + ")");
item.find("span").text(step.label);
});
// Fixes the alignment due to absulutely positioned labels
if (sliderItems.length > 0) {
if (options.orientation !== "vertical" && (tickPlacement === "bottomRight" || tickPlacement === "both")) {
let left = sliderItems.find("li:eq(0) span")[0].getBoundingClientRect().width;
let right = sliderItems.find(`li:eq(${options.dataSource.length - 1}) span`)[0].getBoundingClientRect().width;
$(`#${elementId}`).closest(".custom-form-slider").css({
paddingRight: `${right / 2}px`,
paddingLeft: `${left / 2}px`,
paddingBottom: "1.2em"
});
} else if (options.orientation === "vertical" && (tickPlacement === "bottomRight" || tickPlacement === "both")) {
let maxLabelWidth = 0;
$.each(options.dataSource, function (index) {
var item = sliderItems.find("li:eq(" + (index) + ") span");
let thisWidth = item[0].getBoundingClientRect().width;
if (thisWidth > maxLabelWidth) {
maxLabelWidth = thisWidth;
}
});
$(`#${elementId}`).closest(".custom-form-slider").css({
display: "inline-block",
paddingRight: `${maxLabelWidth + 10}px`,
paddingBottom: "14px"
});
} else if (options.orientation === "horizontal" && (tickPlacement === "topLeft")) {
let left = sliderItems.find("li:eq(0) span")[0].getBoundingClientRect().width;
let right = sliderItems.find(`li:eq(${options.dataSource.length - 1}) span`)[0].getBoundingClientRect().width;
$(`#${elementId}`).closest(".custom-form-slider").css({
paddingTop: "1.2em",
paddingLeft: `${left / 2}px`,
paddingRight: `${right / 2}px`
});
} else if (options.orientation === "vertical" && (tickPlacement === "topLeft")) {
let maxLabelWidth = 0;
$.each(options.dataSource, function (index) {
var item = sliderItems.find("li:eq(" + (index) + ") span");
let thisWidth = item[0].getBoundingClientRect().width;
if (thisWidth > maxLabelWidth) {
maxLabelWidth = thisWidth;
}
});
$(`#${elementId}`).closest(".custom-form-slider").css({
display: "inline-block",
paddingLeft: `${maxLabelWidth + 10} px`,
paddingBottom: "14px"
});
} else {
$(`#${elementId}`).closest(".custom-form-slider").css({
display: "",
paddingLeft: "",
paddingBottom: ""
});
}
}
// Resize again to fix the track since we changed the padding.
thisSlider.resize();
// Then replace the labels since the resize erases them.
sliderItems = $(`#${elementId}`).siblings(".k-slider-items");
$.each(options.dataSource, function (index, step) {
var item = sliderItems.find("li:eq(" + (index) + ")");
item.attr("title", step.label);
item.find("span").text(step.label);
});
}
function getKendoSliderSelection(elementId) {
let thisSlider = $(`#${elementId}`).data("kendoSlider");
let dataSource = thisSlider.options.dataSource;
let value = thisSlider.value();
if (dataSource) {
return dataSource[value];
} else {
return {
label: value,
value: value
};
}
}
function setKendoSliderValue(elementId, newValue) {
// newValue must exist in the dataSource or nothing will change
let thisSlider = $(`#${elementId}`).data("kendoSlider");
let dataSource = thisSlider.options.dataSource;
let newValueIndex = dataSource.findIndex(x => x.value === newValue);
if (newValueIndex > -1) {
thisSlider.value(newValueIndex);
} else {
console.error(`Attempted to set the value of #${elementId} to non-existing value of ${newValue}`);
}
return newValueIndex;
}
function debounce(func, timeout = 300){
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => { func.apply(this, args); }, timeout);
};
}
window.initializeKendoSlider = initializeKendoSlider;
window.getKendoSliderSelection = getKendoSliderSelection;
window.setKendoSliderValue = setKendoSliderValue;
window.resizeKendoSlider = resizeKendoSlider;
Hi. This issue can be replicated in the Telerik dojo for the jQuery Slider.
When tabbing to the decrease and increase buttons and pressing space to invoke the action, nothing happens. I can see the graphical affect of the button being pushed but there is no change in value of the slider.
Tabbing onto the central slider value and moving left and right using the arrow keys works as expected.
Here's what I reckon should happen when using the keyboard with the slider: When the user tabs to the increase/decrease button to give it focus, a press of the spacebar activates the button. The slider value should change accordingly and the focus should stay on the button.
Strangely, when NVDA is active, tabbing to the increase or decrease buttons and pressing spacebar key works the first time. It then shifts focus to the slider itself and I have to start using the left and right arrows instead.
Any thoughts on how to work around this as the built in events are not triggered?

Hello,
I'm reading some datasets from a database and use the values to fill a grid - and on the other hand fill a small form.
The form contains among others a rangeslider. After a quick Google search I was pointed to the Telerik Forums.
So now I do it with the following code-section
var rangeslider = $("#rangeslider").data("kendoRangeSlider");
var rangeValues = [currentDataItem.MinPosition, currentDataItem.MaxPosition];
rangeslider.setOptions({
min: 0,
max: currentDataItem.MaxPositionMeter,
smallStep: 1,
largeStep: 10,
tickPlacement: "both"
});
rangeslider.value(rangeValues);
My problem is :
exemplary section of the data-grid
0, 704, 800
48, 752, 800
96, 800, 800
the first 2 numbers "serve" value-array and 800 as the max-parameter.
First 2 lines get displayed correctly, but the 3rd row behaves wierdly. The selection start-marker is displayed correctly, but whatever data-row was displayed at first, determines where the selection-end marker of the rangeslider is drawn, so it doesn't "move" - and the selection-range is displayed with correct length - but as the selection-end marker is not at the correct position the selection suddenly goes beyond the selection-start marker.
Is there anything I can do to prevent this weird behavior? Is it a problem when the value for selection-end is equal to max?
For reference I include a screenshot of the rangeslider drawn when going from data-row 2 to row 3
The min-value is always 0 for all 3 data-rows
Like subject says - I build in a rangeslider. Now I want it drawn to "scale" => width: 780px ... but every attempt so far has failed
I tried style= in the <div it self, then I found you api description , so I build the exact same code from the api-description in my document.ready() function .. only to be greeted with the subject line "rs.resize() is not a function ...
As the remaining Kendo ui stuff is working and also the rangeslider does "everything else" .. conforms to the properties I set in the definition ...
I'm at the moment without any clue what could lead to the described error message
Every help is welcome
my js-code for that matter$(document).ready(function () {
$("#rangeslider").kendoRangeSlider({
change: rangeSliderOnChange,
slide: rangeSliderOnSlide,
min: 0,
max: 780,
smallStep: 1,
largeStep: 10,
tickPlacement: "both",
});
var rs = $("#rangeslider").getKendoRangeSlider();
rs.wrapper.css("width", "780px");
rs.resize();
});
I have a slider on a page set to a min/max of 0 and 100. The min/max of this slider is variable and changes depending on what a user has selected in a dropdownlist. For example, when the user selects an item in the dropdownlist, I change the slider's min/max value of 10 and 50 using setOptions.
var slider = $("#slider").data("kendoSlider");slider.resize();
This seems to work as the slider updates to the properties I set in setOptions. But after I do this, it doesn't consistently let me jump to a value in the slider. For example, if I try to click the slider line at 40, the slider won't move to it. Sometimes it will, sometimes it won't. If I drag the slider ball to a number it works fine, if I user the increase/decrease arrow buttons it works fine. But clicking on a number in the slider bar does not work.
- This jumping to a number in the slider works fine before I dynamically change the properties using "setOptions".
- This problem occurs regardless of what property in the slider I change using "setOptions".
Any ideas? Thanks.
Are there any updates on this topic ? Since I am using Kendo UI slider with razor view having version 2017.2.621.545 and I am not able to get it works in mobile devices specially on iPhone.
The code is as follows -
@(Html.Kendo().SliderFor(m => m.PercentChanceClose)
.Name("PercentChanceClose")
.ShowButtons(true)
.Tooltip(true)
.Max(100)
.Min(0)
.SmallStep(5)
.LargeStep(10)
.Events( e => e.Change("SliderChange"))
.IncreaseButtonTitle("Perecent(%) Chance Close")
.HtmlAttributes(new { @class = "form-control"})
)
JavaScript function -
function SliderChange(e) {
if (e== null) {
SliderValue(50);
}
else {
SliderValue(e.value);
}
}
function SliderValue(x) {
var top = $("#PercentChanceClose").closest(".k-slider-wrap");
if (x >= 0 && x <= 24) {
$(".k-slider-track", top).css("background-color", "#00ff00");
$(".k-slider-selection", top).css("background-color", "#00ff00");
}
else if (x >= 25 && x <= 74) {
$(".k-slider-track", top).css("background-color", "#ffa500");
$(".k-slider-selection", top).css("background-color", "#ffa500");
}
else {
$(".k-slider-track", top).css("background-color", "#ff0000");
$(".k-slider-selection", top).css("background-color", "#ff0000");
}
}
I'm trying out the native Angular 4 components, and I'm starting with the Slider. I was really surprised not to have value labels for the ticks. You can see that in the current documentation: http://www.telerik.com/kendo-angular-ui/components/inputs/slider/
Not having them as the default wouldn't surprise me much, but there doesn't seem to be a way to turn them on on the API: http://www.telerik.com/kendo-angular-ui/components/inputs/api/SliderComponent/
The slider in kendo-ui had this feature. Am I just missing something?