Calendar Selected Date

9 posts, 0 answers
  1. Chris
    Chris avatar
    43 posts
    Member since:
    Aug 2008

    Posted 01 Apr 2009 Link to this post

    Hi,

    I'm using the regular Rad Calendar.  I default the selected date to today when my page loads.  Is there a way to not allow the user to unselect a date in the calendar so nothing is selected so I don't have to put in extra validation.
  2. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 01 Apr 2009 Link to this post

    Hello Chris,

    Depending on your requirement you can either disable the date selection at all, or cancel a specific selection using the client-side events of our RadCalendar control.
    Date Selection (PresentationType property)
    RadCalendar - OnDateSelecting

    Regards,
    Daniel
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. Chris
    Chris avatar
    43 posts
    Member since:
    Aug 2008

    Posted 01 Apr 2009 Link to this post

    I do need them to be able to select a date.  I've got EnableMultiSelect to false because I only want them picking a single date.  But I also want them to have a date selected at all times.  Because with the default functionality you can select a date, and then select it again to unselect it.  I don't want them to be able to do that.  So I'll try the second option.
  4. Chris
    Chris avatar
    43 posts
    Member since:
    Aug 2008

    Posted 01 Apr 2009 Link to this post

    This is what I have so far:

    <script type="text/javascript">
        function Unselect(sender, eventArgs) {
            var isSelecting = eventArgs.get_isSelecting(); ;
            eventArgs.set_cancel(!isSelecting);
        }
    </script>

    <tim:Calendar ID="calReportDate" runat="server" SkinID="TIMCalendar" EnableMultiSelect="false">
        <ClientEvents OnDateSelecting="Unselect" />
    </tim:Calendar>

    So that works, except that now they can select as many dates as they want.  It ignores the EnableMultiSelect.  So is there a way I can check to see:

    if (date is being selected) {
        if (number of selected dates > 1) {
            unselect the old date
            select the newly selected date
        }
    }

    Its a little hard to describe.  I guess consider it like this: the user has to always have a minimum and maximum of 1 date selected at all times.  So if they try to unselect a date on the calendar, nothing should happen.  And if they try to select a new date, it should unselect the previous date and select the new date.  Similar to how the date picker calendar works, if the calendar portion was always open.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Apr 2009 Link to this post

    Hello Chris,

    I found out an interesting code library submission which explains on how  to implement selecting only a day or a week with RadCalendar. Probably this should give you ideas to achieve your scenario.
    Calendar single day / single week selection

    Thanks
    Princy.
  6. Chris
    Chris avatar
    43 posts
    Member since:
    Aug 2008

    Posted 02 Apr 2009 Link to this post

    Hi,

    Thanks for your reply.  That link solved about 99% of what I wanted.  You pointed me in the right direction and I got my issue solved using that link as reference.  Thanks a lot for the help.
  7. Chris
    Chris avatar
    43 posts
    Member since:
    Aug 2008

    Posted 22 Jun 2009 Link to this post

    Hi,

    I found a solution to my problem a while back with something from the code base.  This is the link:
    http://www.telerik.com/community/code-library/aspnet-ajax/calendar/radcalendar-always-with-selected-date.aspx

    However, on the initial loading of my calendar, I set the selected date to the current day.  When I do this, the first time a user has the ability to select a date, if they go to unselect the current day, they can.  Any other time, the javascript works fine.

    EDIT - I think I solved my own problem, just curious if this could cause something odd to happen with other logic in the control.

    var lastSelectedDate; 
    function OnDateSelecting(calendar, args) { 
        //  Only disable unselecting and multi selecting of dates if the EnableMultiSelect 
        //  is set to false. 
        if (!calendar.get_enableMultiSelect()) { 
            var selectedDates = calendar.get_selectedDates(); 
            if (args.get_isSelecting()) { 
                lastSelectedDate = args.get_renderDay().get_date(); 
                for (var i = 0; i < selectedDates.length; i++) { 
                    var current = selectedDates[i]; 
                    if (current != lastSelectedDate) { 
                        var deselectedDate = [current[0], current[1], current[2]]; 
                        calendar.unselectDate(deselectedDate); 
                    } 
                } 
            } 
            else if (lastSelectedDate == args.get_renderDay().get_date() || lastSelectedDate == null) { 
                args.set_cancel(true); 
            } 
        } 

    I've tested it a little and it seems to be working fine.


  8. Ryan
    Ryan avatar
    2 posts
    Member since:
    Apr 2009

    Posted 25 Jan 2010 Link to this post

    Is there any chance that this functionality could be added into the control?

    I think it's a common scenario to have atleast on selected date i.e. EnableUnSelect property set to false would disallow the user from unselecting the current selected date.
  9. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 28 Jan 2010 Link to this post

    Hello Ryan,

    Thank you for your suggestion, I passed your feature request to our developers.

    Let me know if you need further assistance.

    Best regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top