Porting from connect bug https://connectadmin/Feedback/ConnectTab.aspx?FeedbackID=810755:
Problem Description:
jquery.validate.unobtrusive always unconditionally calls .validate() on all forms in the document, including those that do not use the data-val-* attributes. This makes any subsequent calls to .validate() be ignored and return early, making it impossible to have forms that use jquery.validate (and not jquery.validate.unobtrusive) for validation on the same page as forms that use unobtrusive validation. This in turn makes it unnecessarily difficult to migrate some large and complex single page applications to unobtrusive validation one form at a time. The problem lies in the parse() method, which in turn calls validationInfo() for each form, and calls attach() on the returned info if it's not null. The actual problem is that validationInfo() never returns null, because if there's no validation info attached to a form, validationInfo() creates and attaches it, effectively calling validate() on the form. This is clearly not what the parse() method expects, as it does check for null returned. I suggest adding a second parameter to validationInfo(), say dontCreate, and from the parse method call validationInfo() like this: info = validationInfo(this, false). Needless to say, validationInfo() should skip creation/attaching of validation info to forms that don't have any when the second parameter is true. The rest of the code does not need to change.
Repro Steps:
1. Take any working sample of the original jquery.validate
2. Add <script src="jquery.validate.unobtrusive.js"></script> to the <head> section, right after where jquery.validate.js is included.
3. Watch the sample fail because by the time $(form).validate(...) is called by sample code, jquery.validate.unobtrusive has already called validate() on that form with its own default settings, which makes the second call be ignored and return early.
Comments: Fixed in changeset 684f70b7167c0aaea7600e5cf6a85a165068be95
Problem Description:
jquery.validate.unobtrusive always unconditionally calls .validate() on all forms in the document, including those that do not use the data-val-* attributes. This makes any subsequent calls to .validate() be ignored and return early, making it impossible to have forms that use jquery.validate (and not jquery.validate.unobtrusive) for validation on the same page as forms that use unobtrusive validation. This in turn makes it unnecessarily difficult to migrate some large and complex single page applications to unobtrusive validation one form at a time. The problem lies in the parse() method, which in turn calls validationInfo() for each form, and calls attach() on the returned info if it's not null. The actual problem is that validationInfo() never returns null, because if there's no validation info attached to a form, validationInfo() creates and attaches it, effectively calling validate() on the form. This is clearly not what the parse() method expects, as it does check for null returned. I suggest adding a second parameter to validationInfo(), say dontCreate, and from the parse method call validationInfo() like this: info = validationInfo(this, false). Needless to say, validationInfo() should skip creation/attaching of validation info to forms that don't have any when the second parameter is true. The rest of the code does not need to change.
Repro Steps:
1. Take any working sample of the original jquery.validate
2. Add <script src="jquery.validate.unobtrusive.js"></script> to the <head> section, right after where jquery.validate.js is included.
3. Watch the sample fail because by the time $(form).validate(...) is called by sample code, jquery.validate.unobtrusive has already called validate() on that form with its own default settings, which makes the second call be ignored and return early.
Comments: Fixed in changeset 684f70b7167c0aaea7600e5cf6a85a165068be95