How to validate the RecurrenceRule

4 posts, 0 answers
  1. samy
    samy avatar
    25 posts
    Member since:
    Sep 2011

    Posted 12 Oct 2011 Link to this post

    I'd like to be able to validate the RecurrenceRule, especially the RecursUntil part which should not be greater than a certain fixed date in the future. I've seen plenty of examples regarding the validation of a custom appointment but i couldn't find anything regarding the RecurrenceRule.

    So far what i've found is that i could possibly inherit from RecurrenceDialogViewModel and override the CanConfirm method, but i couldn't find the points where i could attach myself.
    I also tried to attach myself to the PropertyChanged event of the RecurrenceDialogViewModel to disallow the change with an alert, but the RecurrenDialog gets in the way!

    Here is the code sample i used to check the RecursUntil
    private void RSVPlanning_ShowDialog(object sender, ShowDialogEventArgs e)
            {
                var rdvm = e.DialogViewModel as RecurrenceDialogViewModel;
                if (rdvm != null)
                {
                    if (rdvm.RecurrenceRangeType == RecurrenceRangeType.NoEndDate)
                    {
                    // we don't want the "no ending mode" and it's hidden in the template
                        rdvm.RecurrenceRangeType = RecurrenceRangeType.RepeatUntil;
                        rdvm.RecursUntil = DateTime.Now.AddDays(7);
                    }
     
                    rdvm.PropertyChanged += ((innerSender, pcea) => {
                        if (pcea.PropertyName == "RecursUntil")
                        {
                            var rdvmCallback = innerSender as RecurrenceDialogViewModel;
                            if (rdvmCallback.RecursUntil > DateTime.Now.AddDays(7))
                            {
                                RadWindow.Alert("That's too far away! Back to one week from now");
                                rdvmCallback.RecursUntil = DateTime.Now.AddDays(7);
                            }
                        }
                    });
                }
            }
    When you run this code with this method attached to the OpenDialog event of the RadScheduler, the alert window is pushed back between the edit appointment window and the edit reccurence window. Is it a bug, or have i forgotten something (saying the alert to be topmost?)
  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 18 Oct 2011 Link to this post

    Hi Samy,

    This seems a problem in RadWindow which we'll research. For now, please modify your code like this in order to workaround it:

    private void scheduleView1_ShowDialog(object sender, ShowDialogEventArgs e)
    {
        var rdvm = e.DialogViewModel as RecurrenceDialogViewModel;
        if (rdvm != null)
        {
            if (rdvm.RecurrenceRangeType == RecurrenceRangeType.NoEndDate)
            {
                // we don't want the "no ending mode" and it's hidden in the template
                rdvm.RecurrenceRangeType = RecurrenceRangeType.RepeatUntil;
                rdvm.RecursUntil = DateTime.Now.AddDays(7);
            }
     
            rdvm.PropertyChanged += ((innerSender, pcea) =>
            {
                if (pcea.PropertyName == "RecursUntil")
                {
                    var rdvmCallback = innerSender as RecurrenceDialogViewModel;
                    if (rdvmCallback.RecursUntil > DateTime.Now.AddDays(7))
                    {
                        rdvmCallback.RecursUntil = DateTime.Now.AddDays(7);
     
                        var textbl = new TextBlock { Text = "That's too far away! Back to one week from now" };
                        textbl.Loaded += new RoutedEventHandler(textbl_Loaded);
                        RadWindow.Alert(new DialogParameters()
                        {
                            Content = textbl
                        });
                    }
                }
            });
        }
    }
     
    void textbl_Loaded(object sender, RoutedEventArgs e)
    {
        (sender as TextBlock).ParentOfType<RadWindow>().BringToFront();
    }

    Hope this helps.

    Greetings,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. samy
    samy avatar
    25 posts
    Member since:
    Sep 2011

    Posted 19 Oct 2011 Link to this post

    Hello Yana,

    Unfortunately, adding the RoutedEvent to bring the RadWindow alert back to the front doesn't seem to work for me.
    There seems to be a very small amount of time when the alert gets back to the front but the recurrence dialog comes back almost immediately.

    I initially had set the
    rdvmCallback.RecursUntil = DateTime.Now.AddDays(7);
    line after the alert, but i thought it could be the reason for the reappearance of the edit recurrence as the topmost window so i moved it before the Alert call, but no luck.

    Are there any others workarounds, or tests i could do to pinpoint the problem?

    Thanks
  5. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 21 Oct 2011 Link to this post

    Hi Samy,

    The code works as expected at our side, please check the attached project for a reference.

    You could also open the RadWindow using a Dispatcher - try it and let us know the result.

    Regards,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top