I have a custom SAPUI5 in which I want to use slider for date picker, I found example
I have included iquery-ui
lib in Controller.js
(as we will run app in Fiori Launchpad). And included the JS code from indicated post in onAfterRendering()
, which is recommended to use instead of $(document).ready
by UI5.
When I run the app - it says TypeError: $(...).slider
is not a function, although I see in Network tab jquery-ui.js
is being loaded.
I tried also to make it work from index.html
- then there is no error in console, just the slider is absent.
Can someone please advice?
This is my code in onAfterRendering function
$('.slider-time').html(dt_from);
$('.slider-time2').html(dt_to);
var min_val = Date.parse(dt_from) / 1000;
var max_val = Date.parse(dt_to) / 1000;
function zeroPad(num, places) {
var zero = places - num.toString().length + 1;
return Array(+(zero > 0 && zero)).join("0") + num;
}
function formatDT(__dt) {
var year = __dt.getFullYear();
var month = zeroPad(__dt.getMonth() + 1, 2);
var date = zeroPad(__dt.getDate(), 2);
var hours = zeroPad(__dt.getHours(), 2);
var minutes = zeroPad(__dt.getMinutes(), 2);
var seconds = zeroPad(__dt.getSeconds(), 2);
return year + '-' + month + '-' + date + ' ' + hours + ':' + minutes + ':' + seconds;
};
$("#slider-range").slider({
range: true,
min: min_val,
max: max_val,
step: 10,
values: [min_val, max_val],
slide: function (e, ui) {
var dt_cur_from = new Date(ui.values[0] * 1000);
$('.slider-time').html(formatDT(dt_cur_from));
var dt_cur_to = new Date(ui.values[1] * 1000);
$('.slider-time2').html(formatDT(dt_cur_to));