Search code examples
jquerytimepicker

Setting the scroll location without setting a default time


I am using the latest timepicker.co control with the following parameters:

        $('input.timepicker').timepicker({
            interval: 15,
            dynamic: false,
            dropdown: true,
            scrollbar: true
        });

I want to allow any time, but I don't want to set a default. I find it annoying that the display starts at 12:00 AM a d I have to scroll all the way down to more useful times. I don't like the way startTime works, changing the order of things in the list (putting earlier times at the bottom). That just seems confusing.

What I want to do is set it up so that the list starts with a specified time already scrolled into view, BUT NOT SELECTED. Is this possible?

ANSWER:

$('input.timepicker').click(function(){
    if(document.getElementById('<%=MyTextBox.ClientID%>').value == null ||
        document.getElementById('<%=MyTextBox.ClientID%>').value.length == 0) {
        $('.ui-timepicker-viewport').scrollTop(765);
    }
});

Solution

  • You can scroll the content on input click for example to achieve what you want.

    for example

    $('input.timepicker').click(function(){
        $('.ui-timepicker-viewport').scrollTop(1000);
    })
    

    The above snippet will make the times start at 8:00AM

    Here is a working fiddle