Unobtrusive Validation for Inline Datepicker not working, works fine for non-inline Datepicker

Deadly 提交于 2019-12-04 07:32:08

Jason is right. By default, jquery validation skips / ignores non-visible input elements. This goes for input type="hidden" elements, or even text boxes that have / inherit display:none; CSS. There is a setting called ignore, and its default value looks like this:

ignore: ':hidden'

You can override this setting on your page with the following script:

$.validator.setDefaults({
    ignore: ''
});

This tells jquery validate not to ignore validation for non-visible elements. If you use this script, jquery validation should automatically, validate the field unobtrusively without you having to manually validate each time the datepicker field value us changed.

In MVC3 hidden form fields are not validated by the clientside validation script, from what I understand. Why not just make the text field hidden, if thats all you want to do?

@Html.TextBox("", dt, new { @class = "datefield", @type = "date", @id = id, style="display:none;" })

or if you want to keep it as a @Html.Hidden field you will have to manually call the validate plugin on the form each time the datepicker is changed.

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