Validate Resources

2 posts, 0 answers
  1. Heiko
    Heiko avatar
    124 posts
    Member since:
    Oct 2012

    Posted 09 Oct 2012 Link to this post

    I have a custom appointment and I want to validate if any resources are checked. I can find no way to check this before the OK button is clicked. In this forum I found an example so here is what I did:

    public partial class dbAppointment : IAppointment, IExtendedAppointment,  IDataErrorInfo
        {
            ...
            ...
            public string Error
            {
                get
                {
                    return ValidateAppointment();
                }
            }
     
            private string ValidateAppointment()
            {
                string errorString = this.ValidateResources();
     
                return errorString;
            }
     
            private string ValidateResources()
            {
                if(this.AppointmentResource.Count == 0)
                {
                    return "Please choose at least one resource.";
                }
                return null;
            }
        }

    Problem is that AppointmentResources.Count is always zero. It seems that checking a resource does not update the AppointmentResource entity collection. What am I doing wrong? How can I validate that resources are checked?

    Regards
    Neils
  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 15 Oct 2012 Link to this post

    Hello Neils,

    You should use the Resources property when validating the resources in the CustomAppointment, the following code snippet shows how the validation should look like:
    private string ValidateResource()
    {
        if (this.Resources.Count == 0)
        {
            return "This appointment needs to have a resource!";
        }
        return null;
    }

    Note that if you want to alert the user to select a resource if none are selected you should create a custom EditAppointmentDialogStyle and add the needed fields to alert the user when the resource validation is not passed.

    You can read this help article that goes through on how to customize the EditAppointmentDialogStyle.

    Regards,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top