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

[Solved] Possible Bug - ErrorMessageResourceName doesn't work with StringLengthAttribute in grid editing

2 Answers 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Henry
Top achievements
Rank 1
Henry asked on 20 Jul 2011, 09:30 AM
I was using 2011.Q2.712~719.

I attempted to implement multi-language in my application. In localizing validation message, I met the issue.

I have a class which has annotation as below:

[MetadataType(typeof(WorkflowStatusMetaData))]
public partial class WorkflowStatus
{
}
 
public class WorkflowStatusMetaData
{
......
 
    [Required(ErrorMessageResourceName = "Validation_Common_Required", ErrorMessageResourceType = typeof(CoreCulture))]
    [StringLength(5, ErrorMessageResourceName = "Validation_Common_StringLength", ErrorMessageResourceType = typeof(CoreCulture))]
    [Display(Name = "Status Name")]
    public object StatusName { get; set; }

......

and I have a telerik mvc grid control to insert/edit this object. (tested in both client editing and server editing, same issue)

The "Required" attribute was working properly and show localized validation message based on culture setting in the runtime, but the "StringLength" attribute does not show localized message based on the culture setting in the runtime, it always shows "Please enter no more than 5 characters." in validation message.

I've made a test with "plain" controls came with Microsoft MVC Toolkit, It seems working fine on both attribute setting, so I suspect this is a bug of Telerik grid control.

Thanks,
Henry


2 Answers, 1 is accepted

Sort by
0
Henry
Top achievements
Rank 1
answered on 20 Jul 2011, 04:01 PM
Update:

I found the message "Please enter no more than 5 characters" is coming from "jquery.validate.min.js" file. I wonder if this behavior (bypassing StringLengthAttribute custom validation message) is by design, and if I should use localized jquery.validate dynamically.

Please advise, thanks.
Henry
0
Henry
Top achievements
Rank 1
answered on 21 Jul 2011, 03:49 AM
My Temporary (but worked) Solution:

1. Download localized message file of "jquery validate" from http://bassistance.de/jquery-plugins/jquery-plugin-validation/
2. Decompress and find localization file out.
3. Rename downloaded messages_cn.js to jquery.validate.messages_cn.js. (not required, but for more clear.)
4. Place it into "Scripts" folder.
5. Modify "_Layout.cshtml" as below to load localized message as culture setting:
@if (Culture == "zh-CN")
{
    @(Html.Telerik().ScriptRegistrar().DefaultGroup(group => group
        .Add("MicrosoftAjax.js")
        .Add("MicrosoftMvcValidation.js")
        .Add("site.js")
        .Add("jquery.validate.min.js")
        .Add("jquery.validate.messages_cn.js")
        .Combined(false).Compress(false)))   
}
else
{
    @(Html.Telerik().ScriptRegistrar().DefaultGroup(group => group
        .Add("MicrosoftAjax.js")
        .Add("MicrosoftMvcValidation.js")
        .Add("site.js")
        .Combined(false).Compress(false)))   
}

In fact, above steps do not show custom validation message for StringLengthAttribute, it just show localized jquery.validate at all.

Please advise if there is more beautiful method to solve the issue.

In addition, to provide complete supporting localization MVC controls, I think Telerik should fix this issue. Is it possible to use MicrosoftMVCValidation.js instead?

Thanks
Henry




Tags
Grid
Asked by
Henry
Top achievements
Rank 1
Answers by
Henry
Top achievements
Rank 1
Share this question
or