剑道的DatePicker验证失败自定义日期格式 [英] Kendo DatePicker fails validation for custom date format

查看:559
本文介绍了剑道的DatePicker验证失败自定义日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是剑道的DatePicker编辑日期字段在我的ASP.NET MVC 4项目被显示在剑道网格。为了具备的DatePicker正在使用的日期字段使用自定义日期格式的字符串,我更新下的 Date.cshtml 文件中的 EditorTemplates 文件夹为以下内容:

I'm using Kendo DatePicker to edit a Date field being displayed in a Kendo Grid in my ASP.NET MVC 4 project. In order to have the DatePicker being used for the Date field use custom date format string, I updated the Date.cshtml file under the EditorTemplates folder to the following:

@(Html.Kendo().DatePickerFor(m => m).Format("dd/MM/yyyy"))

通过这样做,我设法有DatePicker的显示格式,我想它。然而,无论是通过从弹出日历中手动键或选择一些输入输入日期的验证失败。

By doing that, I managed to have the DatePicker display the format as I want it to. However, it failed validation for some of the dates entered for input, either via manual key in or selection from the popup calendar.

经进一步调查,我可以说的DatePicker验证是基于一个 M / D / Y值格式的日期。这种假设是基于我的书院是2012年12月1日是一个有效的日期作出,而13/1/2012没有。

Upon further investigation, I can say that the DatePicker is validating the date based on a M/d/Y format. That assumption was made based on my foundings that 12/1/2012 is a valid date, whereas 13/1/2012 is not.

我也试过在 Date.cshtml .ParseFormat(DD / MM / YYYY)到的DatePicker声明的末尾code>,但它不能解决任何事情。所以,我要说,这绝对是一个错误,我稍后会将此情况报告给Telerik的。

I also tried adding .ParseFormat("dd/MM/yyyy") to the end of the DatePicker declaration in Date.cshtml but it does not fix anything. So I would say that this is definitely a bug and I will report this to Telerik later.

但目前,我正在寻找一个解决办法有这方面的工作。我发现我可以重写 kendo.ui.validator.rules.mvcdate 在Javascript中有我自己的验证功能。而在Chrome这项工作很好,它不会在IE9工作。

But for the time being, I'm looking for a workaround to have this working. I find that I can override kendo.ui.validator.rules.mvcdate in Javascript to have my own validation function. While this work fine in Chrome, it does not work in IE9.

所以,任何想法我怎么能做出的DatePicker接受 DD / MM / YYYY 输入格式?先谢谢了。

So, any ideas how I can make the DatePicker to accept dd/MM/yyyy input format? Thanks in advance.

推荐答案

在内部,为ASP.NET MVC(不显眼的客户端验证)的日期验证规则,使用<一个href=\"http://docs.kendoui.com/getting-started/framework/globalization/dateparsing\">kendo.parseDate(string)方法,它在内部将使用的predefined日期模式的,如果没有格式/ s的/限定。我想,在你的情况下,默认的文化是EN-US,这就是为什么验证失败,因为DD / MM / YYYY格式的日期被视为无效。一种可能的解决方案是重写的日期验证规则(像你一样),并使用特定的格式解析字符串。另一种选择是,为页面设置差异的文化设置。 例如,对于去-DE文化短日期格式为DD / MM / YYYY。

Internally, the date validation rule for ASP.NET MVC (the unobtrusive client validation), uses kendo.parseDate(string) method, which internally will use the predefined date patterns if no format/s is/are defined. I suppose that in your case the default culture is "en-US" and that is why validation fails, because dates with "dd/MM/yyyy" format are considered as not valid. One possible solution is to override the date validation rule (as you did) and parse the string using a specific format. The other option is to set diff culture settings for the page. For instance, the short date format for the "de-DE" culture is "dd/MM/yyyy".

这篇关于剑道的DatePicker验证失败自定义日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆