MVC3 unobtrusive validation: how to remove/re-attach validation from a group of elements?

后端 未结 1 1913
暖寄归人
暖寄归人 2020-12-19 08:42

Here\'s the use case:

I have this long form with group of field that only becomes visible if the user makes a certain selection in one of the visible inputs. Reading

相关标签:
1条回答
  • 2020-12-19 09:27

    Do not remove and re-attach rules. Just disable or enable inputs. Disabled fields do not participate in validation, neither do they get submitted to server.

    //disable inputs. No validation will occur on these
    $('.data-panel').find('input[type="text"], textarea, select').attr('disabled', 'disabled');
    
    //enable inputs. Validation is re-enabled
    $('.data-panel').find('input[type="text"], textarea, select').removeAttr('disabled');
    
    0 讨论(0)
提交回复
热议问题