New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempting to use with require.js causes "ko is not defined" #259
Comments
Unfortunately knockout validation doesn't play well with requirejs at the moment. The problem is that knockout will use requirejs and so doesn't set the global You can work around this for the time being using the pattern below, but it isn't particularly nice. require.config({
baseUrl: "/scripts",
paths: {
"knockout": "knockout-2.2.1",
"knockout.validation": "knockout.validation"
},
shim: {
"knockout.validation": ["knockout"]
}
});
require(["knockout"], function (ko) {
//manually set the global ko property
window.ko = ko;
//then bring in knockout validation
require(["knockout.validation"], function() {
var ViewModel = function () {
var self = this;
self.field = ko.observable("Required Value").extend({ required: true });
};
ko.applyBindings(new ViewModel());
});
}); We probably should support requirejs going forward though... |
I'm already setting some global stuff for other reasons, so it's not too bad for me. Thanks for the speedy response. |
Bummer. |
is this in a release? |
not in a release, but if you grab the source from GitHub then requirejs is properly supported |
gotcha. |
Hi, I'm experiencing some difficulties regarding this. Any update on a fix without using the workaround above? |
I'm configuring require like so:
But when I later use the validation:
define(['jquery', 'knockout', 'komapping', 'Views/add-report-wizard-model', 'token', 'validation'], function ($, ko, mapping, ViewModel, token, validation) { ... });
It fails with "ko is not defined." Is there an example somewhere of how I need to reference knockout.validation with require.js?
The text was updated successfully, but these errors were encountered: