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

Validation via DataAnnotation Example?

3 Answers 61 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jonathan
Top achievements
Rank 1
Jonathan asked on 07 Mar 2017, 05:55 PM
Is their an example of how to implement form validation via Annotations?

3 Answers, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 10 Mar 2017, 09:46 AM
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!
0
Jonathan
Top achievements
Rank 1
answered on 10 Mar 2017, 06:49 PM

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? 

 

 

0
Ivaylo Gergov
Telerik team
answered on 16 Mar 2017, 01:14 AM
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!
Tags
DataForm
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Jonathan
Top achievements
Rank 1
Share this question
or