Custom ValidationResult

4 posts, 0 answers
  1. Marcel
    Marcel avatar
    21 posts
    Member since:
    Jul 2011

    Posted 06 Nov 2014 Link to this post

    Hi there,

    I'm developing a view for a model which makes use of DataAnnotation validation. The RadGridView is automatically showing the error messages triggered by invalid input. But, the model's validators are returning a custom implementation derived from System.ComponentModel.DataAnnotations.ValidationResult which contains additional properties. I need to somehow bind those additional properties in the view (e.g. in the GridViewEditorPresenter) but it seems like the RadGridView is transforming the ValidationResult to some Telerik specific class (GridViewCellValidationResult) and of course the additional information gets lost. Is there an easy way (or maybe a work-around) to somehow access the original ValidationResult in the GridViewCellValidationResult-Template?

    Regards,
    Marcel

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 10 Nov 2014 Link to this post

    Hello Marcel,

    Indeed, you are right. We wrap all validation errors in GridViewCellValidationResult. What is the information that you want to have that we hide ? What is the exact scenario that you want to accomplish ? 


    Regards,
    Maya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Marcel
    Marcel avatar
    21 posts
    Member since:
    Jul 2011

    Posted 09 Dec 2014 in reply to Maya Link to this post

    Hi Maya,

    I need to somehow transfer more information from the validator in the model to the GridViewEditorPresenter template in the view. My first approach was to inherit ValidationResult and add some properties there. This would be for example a "Priority" property which should somehow express the importance level of the validation error (e.g. yellow/orange/red etc.). I need more than just valid/not valid plus error message. Because of the transformation from .NET's ValidationResult to Telerik's GridViewCellValidationResult, this approach was a dead end.  

    My next thought was to somehow get hold of the ValidationContext (or the validated object instance) inside the GridViewEditorPresenter, but it does not seem to be anywhere in the DataContext. So I can't find a way to connect the ValidationResult to the validated value/property in any way inside the GridViewEditorPresenter. Maybe this is just no valid use case for the build-in validation mechanism with data annotations and I need to use a totally different approach…

    Regards,
    Marcel
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 09 Dec 2014 Link to this post

    Hi Marcel,

    I am afraid that if you want to customize the validation in a way, you would better follow some of the approaches that give a bit more freedom. For example, implementing IDataErrorInfo/ INotifyDataError, handling validating events of RadGridView. 
    Check out "Validating"article (and the links towards our SDK examples at the end) for a reference. 

    Regards,
    Maya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top