Client-side validation of input type date does not work

大憨熊 提交于 2019-12-05 04:19:01
spot

I had the exact same problem and was maddened beyond belief when viewing a mobile site I'm developing on my iPhone. The discussion in the issue below solved it for me.

https://github.com/jzaefferer/jquery-validation/issues/20.

Also, to go the distance with this in a seamless way, I created the following razor editor template for Date data types:

@model DateTime?
@Html.TextBox("myDate", ViewData.Model.ToIso8601FullDate(), new { type = "date", @class = "text-box single-line" })

and a handy extension method to feed the html 5 date input type a format it enjoys working with according to the spec for input type=date:

public static string ToIso8601FullDate(this DateTime? d)
{
    if (!d.HasValue) return null;

    return d.Value.ToString("yyyy-MM-dd");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!