dynamically remove an element's required attribute in ASP MVC?

橙三吉。 提交于 2019-12-05 18:32:24

You can use the .rules() method built into jQuery, you don't need to manually remove attributes.

To remove:

$("#txtTempHireEndDate").rules("remove", "required")

To add:

$("#txtTempHireEndDate").rules("add", "required")

you can use rules function in jquery.validate

$("..").rules("add",....)
$("..").rules("remove",...)

http://jqueryvalidation.org/rules

You must revalidate the form.

Just call the validate function from form, like this:

$('#FormId').valid();

You can also validate the control you've removed the attribute:

$('#txtTempHireEndDate').valid();

$("#dailyFlow").removeAttr('data-val-required');

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