knockout.validation module has stopped working in 3.5.0-rc

Created on 15 Oct 2018  路  3Comments  路  Source: knockout/knockout

Hi guys, knockout validation module has stopped working in 3.5.0-rc, saying this:

knockout-latest.js:84 Uncaught Error: ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node
    at a.qc (knockout-latest.js:84)
    at Object.ko.applyBindings (knockout.validation.js:1472)
    at HTMLDocument.<anonymous> (startup.designtime.ts:50)

Simple repro: https://jsfiddle.net/azaslonov/4z62mw1r/

Considering they didn't release since 2015, there is probably something got broken in KO itself.
https://github.com/Knockout-Contrib/Knockout-Validation/releases

Can you guys please have a look?

Most helpful comment

See https://github.com/knockout/knockout/issues/2388 - to summarize, prior to 3.5 it was unspecified what it meant by passing a non-DOM-node value as a 2nd parameter to ko.applyBindings; in 3.5 if you pass a 2nd parameter it needs to be a DOM node.

Knockout Validation overrides ko.applyBindings and always passes a 2nd parameter to the original ko.applyBindings. In your sample, knockout therefore throws an error because the value of the parameter that gets passed to the original ko.applyBindings is undefined, which is not a DOM node.

Probably, the easiest way if you use Knockout Validation is to always passing a 2nd parameter explicitly with the value document.body. In your sample, change ko.applyBindings() to ko.applyBindings(undefined, document.body)

All 3 comments

See https://github.com/knockout/knockout/issues/2388 - to summarize, prior to 3.5 it was unspecified what it meant by passing a non-DOM-node value as a 2nd parameter to ko.applyBindings; in 3.5 if you pass a 2nd parameter it needs to be a DOM node.

Knockout Validation overrides ko.applyBindings and always passes a 2nd parameter to the original ko.applyBindings. In your sample, knockout therefore throws an error because the value of the parameter that gets passed to the original ko.applyBindings is undefined, which is not a DOM node.

Probably, the easiest way if you use Knockout Validation is to always passing a 2nd parameter explicitly with the value document.body. In your sample, change ko.applyBindings() to ko.applyBindings(undefined, document.body)

Thank you, I think I can live with this for now.

Alternatively, patch knockout-validation and change the call origApplyBindings(viewModel, rootNode) to origApplyBindings.apply(this, arguments).
If you are using its ko.applyBindingsWithValidation you probably need to update it as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewchch picture andrewchch  路  3Comments

IPWright83 picture IPWright83  路  7Comments

andersekdahl picture andersekdahl  路  6Comments

johnpapa picture johnpapa  路  9Comments

lovedota picture lovedota  路  4Comments