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

set_cancel using Datepicker

3 Answers 100 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Elgin
Top achievements
Rank 1
Elgin asked on 29 Feb 2012, 07:23 PM
I am having an issue with set_cancel firing

 

 

<telerik:RadDatePicker runat="server" ID="DateNeededDP">
<
ClientEvents OnDateSelected="DateSelected" />
</
telerik:RadDatePicker


<telerik:RadDatePicker runat="server" ID="EffDateDP" >
<
ClientEvents OnDateSelected="DateSelected" />
</
telerik:RadDatePicker>

 

<telerik:RadDatePicker runat="server" ID="EndDateDP">
<
ClientEvents OnDateSelected="DateSelected" />
</
telerik:RadDatePicker>

 

 

function DateSelected(sender, eventArgs) {

    formdirty();

    var node = sender.get_id().substr(sender.get_id().indexOf("_MainContent_") + 13);

    if (node == "EndDateDP") {

        var datePicker = $find("<%= EffDateDP.ClientID %>");

        var effdate = datePicker.get_selectedDate();

        var enddate = sender.get_selectedDate();

        if (enddate <= effdate) { 
                    eventArgs.set_cancel(true);

                    alert("End Date must be greater than Effective Date");

                }

        }

         if (node == "EffDateDP") {

        var datePicker = $find("<%= EndDateDP.ClientID %>");

        var enddate = datePicker.get_selectedDate();

        var effdate = sender.get_selectedDate();

        if (enddate <= effdate) { 
                    eventArgs.set_cancel(true);

                    alert("Effective Date must be less than End Date");

                }

        }

    if (node == "DateNeededDP") { 
        var Neededdate = sender.get_selectedDate();

        var today = new Date();

        if (Neededdate < today) {

                    eventArgs.set_cancel(true);

                    alert("Needed Date must be greater than Today");

                }

        }

}


The alerts fire correctly but it is not canceling the selected date.  And help would be great.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Mar 2012, 06:21 AM
Hello,

For cancelling the selected date try the following code.
JS:
function DateSelected(sender, eventArgs)
{
sender.clear();
}

Thanks,
Princy.
0
DonKitchen
Top achievements
Rank 1
answered on 13 Jul 2012, 12:42 PM
That doesn't cancel (i.e. revert) the date.

Is there a way to set_cancel and revert to the old value without another event firing?

I'm trying to cancel a user's change and revert to the old (previous) value but am caught in a loop as the DateSelected event keeps firing when I set the date back to the old date.

Here's an example.  What can I do to prevent this?  There doesn't seem to be a "changing" event for the Datepicker that works!

function DateSelected(sender, args) {
 
            var go = window.confirm("Changing the start will cause all data to be reloaded. Do you wish to continue?");
 
            if (!go) {
                var oldDate = args.get_oldDate();
                sender.set_selectedDate(oldDate);  
            }
 
            args.set_cancel(!go);
        }
0
Princy
Top achievements
Rank 2
answered on 16 Jul 2012, 09:35 AM
Hello,

Try the following to get the old date.
JS:
function DateSelected(sender, args)
 {
  var dt= args.get_oldValue();
 }

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