I have a main module in RequireJS:
require([
'jquery',
'jquery.validate',
'jquery.validate.unobtrusive'
], function ($) {
$(document).ready(function () {
var validator = $("form").validate();
if ($("#txtFirstName").val() !== "")
validator.element("#txtFirstName");
});
});
When I load this page, I get a JavaScript error:
TypeError: $(...).validate is not a function var validator = $("form").validate();**
I don't now why? All scripts are loaded:
You'll need to configure
shim
to "wire" the dependencies correctly:More details (and examples) in the official documentation (look for the "For "modules" that are just jQuery or Backbone plugins..." section).