Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a legacy project which I have been approved to work in a knockout.js module. This is great, however the application is extremely complex and I need to use some of the pre-built form validation of our application.

My form validators work fine until a dynamic template gets switched out. I can't for the life of me figure out the error. Nothing in the console and my vast debugging efforts have been fruitless.

I'm thinking that my solution could be something along the lines of limiting the scope of the knockout application similar to how one can declare ng-app in angular.js.

I can't find a working example of how to do this or any documentation relevant to knockout.js

share|improve this question
    
Post what code you've got and this should probably be migrated to Stackoverflow. –  CodeART Sep 20 '13 at 9:17
add comment

closed as unclear what you're asking by GlenH7, gnat, maple_shaft Sep 20 '13 at 9:27

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 1 down vote accepted

The scope to which elements knockout binds itself with is determined from the way you call ko.applyBindings. It takes two parameters, an object to be used as the root view model and an element to "apply" the bindings on. The latter parameter is optional and usually tutorials and documentation leaves it out like this:

ko.applyBindings(viewModel);

By default, without the second parameter, knockout will apply the bindings on the whole document. If you want to limit the bindings from one specific HTML element you can specify it as the second parameter to be used as a parent instead of the document. Pretty much like this:

var parent = document.getElementById('someElementId');
// or if you are using jquery, use $('#someElementId')[0]

ko.applyBindings(viewModel, parent);

It is briefly described in this section of the knockout docs.

share|improve this answer
    
Perfect. Just what I was looking for. Thank you @Spoike –  bluetoft Sep 20 '13 at 12:06
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.