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

[Solved] Calendar Selected Date

8 Answers 375 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 01 Apr 2009, 01:09 PM
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.

8 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 01 Apr 2009, 04:56 PM
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.
0
Chris
Top achievements
Rank 1
answered on 01 Apr 2009, 05:26 PM
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.
0
Chris
Top achievements
Rank 1
answered on 01 Apr 2009, 05:57 PM
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.
0
Princy
Top achievements
Rank 2
answered on 02 Apr 2009, 06:34 AM
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.
0
Chris
Top achievements
Rank 1
answered on 02 Apr 2009, 12:50 PM
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.
0
Chris
Top achievements
Rank 1
answered on 22 Jun 2009, 03:10 PM
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.


0
Ryan
Top achievements
Rank 1
answered on 25 Jan 2010, 03:34 PM
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.
0
Daniel
Telerik team
answered on 28 Jan 2010, 02:45 PM
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.
Tags
Calendar
Asked by
Chris
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Chris
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Ryan
Top achievements
Rank 1
Share this question
or