minimum value for datetimepicker (client side)

2 posts, 0 answers
  1. Alex Lawson
    Alex Lawson avatar
    43 posts
    Member since:
    May 2008

    Posted 07 Jul 2008 Link to this post

    I want to limit the entered time value to a min-max range fro the datetimepicker, so that if a user enters 7:03 am it will be corrected to 9:00am for example.

    Is this achievable in client side JS code?
  2. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 10 Jul 2008 Link to this post

    Hi Alex,

    It is possible to catch the ClientEvents of the DateInput as shown below:
    <telerik:RadDateTimePicker ID="RadDateTimePicker1" runat="server"
        <DateInput runat="server"
            <ClientEvents OnValueChanged="CheckTime" OnMouseOut="CheckTime"> </ClientEvents> 
        </DateInput> 
    </telerik:RadDateTimePicker> 

    Afterward you can choose how to handle the event from JavaScript. Here is a possible approach:
    var time = new Date(sender.GetDisplayValue());  
    minTime.setDate(time.getDate()); 
    maxTime.setDate(time.getDate()); 
     
    if(time < minTime) 
        time.setTime(minTime.getTime()); 
        sender.set_value(time.toString());         
    else if (time > maxTime) 
        time.setTime(maxTime.getTime()); 
        sender.set_value(time.toString());         

    Kind regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top