日期格式为yyyy-MM-dd的Kendo UI DatePicker警告

MJD*_*ria 10 format date datepicker kendo-ui

我的页面上有关于无效日期格式的警告,如下所示.该警告由Kendo UI DatePicker组件生成.我在网上找不到解决方案,我的应用程序是本地化的pt-BR.如何解决这个问题呢.

<p>@(Html.Kendo().DatePicker().Name("periodoDocumento").Value(DateTime.Now))</p>
Run Code Online (Sandbox Code Playgroud)

Google Chrome中出错:

The specified value '06/07/2015' does not conform to the required format, 'yyyy-MM-dd'.
Run Code Online (Sandbox Code Playgroud)

我必须使用日 - 月 - 年格式来满足我的客户需求.

Mis*_*ima 16

我找到了解决方案

@(Html.Kendo().DatePicker().Name("periodoDocumento").Value(DateTime.Now).HtmlAttributes(new { @type = "" }))
Run Code Online (Sandbox Code Playgroud)

因此jquery将停止使用默认格式将此字段解析为日期.


Tim*_*ant 5

设置字段的类型以text防止浏览器和jQuery Validator将其视为日期。与指定无效的输入类型格式(如empty string)相比,这更加干净。

@(Html.Kendo().DatePicker()
    .Name("DateFieldName")
    .Value(Model.DateFieldName)
    .HtmlAttributes(new { @type=  "text"})
    )
Run Code Online (Sandbox Code Playgroud)

但是,这仍然有些技巧-它只是抑制了浏览器和/或验证工具对日期字段所做的验证。更好的解决方案(适用于长期修复)是为了确保日期字符串填充这些日期字段符合HTML5日期字段生活水平的阐述了ISO 8601,例如,2017-02-10

另请参考此新问题,尤其是有关Chrome现在要求在HTML5日期字段中使用正确格式的问题。

Kendo UI datepicker与Chrome 56不兼容


Ste*_*ene 2

添加格式属性:

@(Html.Kendo().DatePicker().Format("dd/MM/yyyy").Name("periodoDocumento").Value(DateTime.Now))
Run Code Online (Sandbox Code Playgroud)

http://docs.telerik.com/kendo-ui/api/javascript/ui/datepicker#configuration-format