This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I'm having trouble finding a way to localize property names and error messages for Server Side and Unobtrusive validation. I don't see a way to set the DisconnectedDisplayNamingStrategy and Unobtrusive Validation doesn't appear to use either strategy when the unobtrusive attributes are generated. Thanks, Jason Moore |
|
|
A DisplayNamingStrategy is only used when the entity is attached to a UnitOfWork, for unobtrusive validation we don't have the ability to refer to a display naming strategy which is why this is not applied. Does this relate just to unobtrusive validation or does it also cover a server side situation where you are not seeing this applied?
|
|
|
I'm just trying to find a way to deliver consistently localized error messages to the user; regardless of whether they are generated on the client or server. I understand that there is nothing you can do about the unobtrusive validators... I was also wondering; How do you set the error message on the Mindscape Validators? |
|
|
Is there any chance we could get something like IDisplayNameStrategy, except for Error messages? IErrorMessageStrategy perhaps? It would be added to DataAnnotationBuilder, When you are creating the ValidationAttribute, the error message could be passed to the ErrorMessageStrategy before setting the ErrorMessage on the ValidationAttribute.
Thanks, Jason |
|
|
In terms of validators if you are meaning the DataAnnotation validation attributes we construct then the messages are assigned based off the validation attribute, as mentioned these cannot refer to the context at the time since we don't have an entity attached to a UOW to refer back to a context with. If you are referring to the LightSpeed validation attributes then the message can be assigned using the Message property on the attribute. In terms of the DataAnnotation validation you could implement your own version of our builder class and set your custom validation messages as required - I can send you the source for these bits if that would be of use?
|
|
|
I'm looking for a dynamic way to override the error message without having to maintain my own version of the LightSpeed source code. I haven't been able to locate a hook that would allow me to change the error message on the LightSpeed validation attribute or replace the builder class. The method I was suggesting shouldn't need a reference to the context or UnitOfWork, it would just give the user an access point to replace the message, in our case, we would be replacing the message with a value stored in our localization cache. Thanks, Jason |
|
|
Implementing your own version of the builder class for mapping the DataAnnotations sounds like the best way to handle this then, there isnt anything natively available to cater for this but that class is fairly lightweight and standalone so it wont be require much to implement your own. Let me know if you need the source code for the existing version.
|
|
|
How would you plug in the custom builder class? I don't see any hooks to replace it. |
|
|
You would use this in preference to the existing ValidatorProvider, e.g.
Which in turn would call the custom builder class.
|
|
|
The DataAnnotationBuilder is also used by EntityDataAnnotationProvider, is there a way to replace the builder here as well to ensure that DataAnnotations are delivered consistently? |
|
|
No, we don't have any override for this, you would need to use a custom version of Mindscape.LightSpeed.Web to make customisations here.
|
|