This is a migrated thread and some comments may be shown as answers.

RadDateTimePicker

1 Answer 37 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Sonia
Top achievements
Rank 1
Sonia asked on 27 Nov 2013, 11:52 AM
Hi guys,

How can i set different increment setting step for hour field and minute field.

I mean i would like to increment/decrease one hour when pressing up/down arrows. But i would like to increment/decrease 15 minutes when pressing up/down arrows.

Thank you for your help.
Sonia.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Nov 2013, 05:55 AM
Hi Sonia,

Please have a look into the following code snippet to increase/decrease hour and minute  based on up/down key.

ASPX:
<telerik:RadDateTimePicker ID="RadDateTimePicker" runat="server" onkeydown="key(event);">
    <TimeView TimeFormat="HH:mm" runat="server">
    </TimeView>
</telerik:RadDateTimePicker>

JavaScript:
<script type="text/javascript">
    function key(e) {
        var picker = $find("<%=RadDateTimePicker.ClientID%>");
        //get the selected date and time
        var arr = picker._dateInput.get_value().split(' ');
        var date = $.trim(arr[0]); //date
        var time = $.trim(arr[1]); //time(both hour and minute)
        var temp = time.split(':');
        hr = temp[0]; //hour
        min = temp[1]; //minute
        var am = $.trim(arr[2]);
        if (e.keyCode == 38) {
            //upkey press
            min = parseInt(min) + 15; // minute is incremented by 1
            picker._dateInput.set_value(date + " " + hr + ":" + min + ":" + " " + am);
        }
        else if (e.keyCode == 40) {
            //down keypress
            min = parseInt(min) - 15; // minute is decremented by 1
            picker._dateInput.set_value(date + " " + hr + ":" + min + ":" + " " + am);
        }
    }
</script>

Thanks,
Princy. 
Tags
Calendar
Asked by
Sonia
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or