MVC 3 unobtrusive validation - conditionally disable/enable validation

前端 未结 2 1510
无人及你
无人及你 2020-12-20 22:44

I have a form that has an option to enter dimensions for:

  • Width & Height
  • Width
  • Height

And I have two container div

相关标签:
2条回答
  • 2020-12-20 23:18

    So it seems that this is the answer to my question (I went hunting again on Google hard to search for things that didn't relate to "hidden" fields):

    https://stackoverflow.com/a/7673985/491950

    e.g.

    $("#height-container input[type='text']").attr("disabled", "disabled");
    

    Thanks for your answers.

    0 讨论(0)
  • 2020-12-20 23:31

    You can set up the jQuery validator that's processing your unobtrusive validation to ignore hidden elements:

    jQuery.validator.defaults.ignore = ":hidden";
    
    // the line above is outside any $(document).ready(...) or similar
    $(document).ready(function(){
        ...
    });
    ...
    
    0 讨论(0)
提交回复
热议问题