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


is there way, in asp mvc project using unobtrusive validation, dynamically remove required attribute element?

the element decorated required annotation in view model. thought remove removing html attribute, "data-val-required," jquery client validation still treats element required. impossible manipulate element's validation manipulating unobtrusive validation attributes?

this tried, didn't work. wanted remove required attribute if check box unchecked.

$("#chktemphire").click(function () {      var checked = $(this).attr("checked");     var attr = $("#txttemphireenddate").attr("data-val-required");     var hasattr = false;      if (typeof attr !== typeof undefined && attr !== false)         hasattr = true;      if (!checked && hasattr)         $("#txttemphireenddate").removeattr("data-val-required"); }); 

am missing something, or not possible?

thank you!

you can use .rules() method built jquery, don't need manually remove attributes.

to remove:

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

to add:

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

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -