Validation via DataAnnotation Example?

Thread is closed for posting
4 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    2 posts
    Member since:
    Mar 2017

    Posted 07 Mar Link to this post

    Is their an example of how to implement form validation via Annotations?
  2. Ivaylo Gergov
    Admin
    Ivaylo Gergov avatar
    691 posts

    Posted 10 Mar Link to this post

    Hello,

    Currently the Validation in RadDataForm can be achieved either if your item implements ISupportEntityValidation or if you provide the implementation of the interface through the RadDataForm.EntityProvider. I have prepared a sample project which demonstrates the second approach. Please, see the attached file.

    I hope this helps. Let me know should you need further assistance.

    Regards,
    Ivaylo Gergov
    Telerik by Progress
    Leverage your XAML skill to create beautiful Windows 10 apps for phone, tablet and desktop. Try UI for Universal Windows Platform today!
  3. Jonathan
    Jonathan avatar
    2 posts
    Member since:
    Mar 2017

    Posted 10 Mar Link to this post

    This helped me get the basic structure in place, but I still don't see how to use Data Annotations from my model in validation.

    I could create hardcoded validation for each form in my application, but thats not really a valid solution.

    In ValidatePropertyAsync I can access the Entity object and its properties, but I can't access its annotations.  I can see them via Reflection, but not utilize them.

    Here's what I'm seeing

            [Telerik.Data.Core.Display(Header = "Value")]
            [Telerik.Data.Core.Required]
            [StringLength(3)]
            public string SomeValue
            

    The "Required" annotation sets "IsRequired" on the property that I can use in validation.  How do I access the StringLength annotation and use it in the validation process? 

     

     

  4. Ivaylo Gergov
    Admin
    Ivaylo Gergov avatar
    691 posts

    Posted 15 Mar Link to this post

    Hello,

    Sorry for the late response.

    Through the Entity you have access to your business item. For example: 
    var item = entity.GetEntityProperty("Value").DataItem;

    I hope this helps.

    Regards,
    Ivaylo Gergov
    Telerik by Progress
    Leverage your XAML skill to create beautiful Windows 10 apps for phone, tablet and desktop. Try UI for Universal Windows Platform today!
Back to Top