gvas / knockout-jqueryui

Knockout bindings for the jQuery UI widgets.
http://gvas.github.com/knockout-jqueryui/
MIT License
103 stars 38 forks source link

[ko3] Error: You cannot apply bindings multiple times to the same element. #26

Closed sammuell closed 10 years ago

sammuell commented 10 years ago

When extending the dialog binding ko v3.0 throws the following error: You cannot apply bindings multiple times to the same element. However the dialog stays fully functional. Ko v2.3 does not throw an error.

ko v2.3.0: http://jsfiddle.net/QJj7s/4/ ko v3.0.0: http://jsfiddle.net/QJj7s/3/

sammuell commented 10 years ago

Update: not applying the view model to < body> seems to do the trick, but it still leaves the question why it throws an error in v3.0 but not in v2.3. http://jsfiddle.net/QJj7s/5/

gvas commented 10 years ago

In my browser the exception is thrown by both of your original fiddles, as expected. Chrome 33.0.1750.117 m.

sammuell commented 10 years ago

Now I'm also getting an error for v2.3. Weird. Must have been an issue with firebug (ff 27.0.1), I restarted firefox between. Why is it to be expected to fail? It's basically an extended example from the documentation.

gvas commented 10 years ago

It's expected because the code to check whether an element is already bound was implemented in ko v2.3. From it's release notes:

Applying binding twice to the same nodes fails in strange ways (now it fails with an obvious error message)

The documentation is a little bit outdated, I should update it. The dialog's example was written before ko v2.3 was released.

The workaround, as you have figured out, is to apply the bindings on a wrapper div instead of the HTML body. This way jQuery UI will move the dialog's element after the wrapper div, and knockout won't try to bind it again.

sammuell commented 10 years ago

The workaround, as you have figured out, is to apply the bindings on a wrapper div instead of the HTML body. This way jQuery UI will move the dialog's element after the wrapper div, and knockout won't try to bind it again.

Yes, that's what I figured when I inspected the changes in markup.

I did not check the ko version in the example, that's what confused me. Guess you should update the docs ;-)

gvas commented 10 years ago

I've updated the docs.