Hi All,
In every CustomValidation example I've seen you can simply decorate your metadata properties with a [CustomValidation] tag and then either return a new ValidationResult object with an error or return ValidationResult.Success (which appears to evaluate to
null). Is ValidationResult.Success supposed to clear the error on the field? In my test applications I've created on 2 separate machines, it doesn't.
I've created a data model from my db, added a domain service and used the service in the client app to get the data. The data appears fine in the grid that I've thrown on there. I can edit the data etc - this all works fine.
I decorated one of the properties in the metadata with the following code:
<CustomValidation(GetType(AccountValidator), "ValidateAccountName")>
Public Property AccountName As String
And created a class to handle the validation:
Public Class AccountValidator
Public Shared Function ValidateAccountName(ByVal name As String) As ValidationResult
If name.Contains("0") Then
Return New ValidationResult("The name cannot contain the character '0'")
End If
Return ValidationResult.Success
End Function
End Class
When I edit the grid and type some text that doesn't contain '0' everything is ok. When I add a '0' in the text I get the red validation popup as expected, however, clearing the '0' from the text doesn't appear to remove the error. I've stepped through the
code and I'm definitely getting a ValidationResult.Success returned from the validation procedure.
Does this functionality work in RC2? Do I need to create a custom validation attribute instead? I would rather have 1 class which contained a list of validation functions for a particular group of entities than to create a custom validation attribute for
every single property.
Thanks for any help :)