Skip to content

Error message "isValid is not defined" after upgrade to Knockout.Validation 2.0.3 #661

@verheyenkoen

Description

@verheyenkoen

I just upgraded Knockout.Validation to the latest release (as I need validation on the new textInput binding) and on this existing binding:

<form data-bind="with: new">
    ....
    <button data-bind="enable: isValid, click: $parent.submit">Submit</button> // or isValid()
</form>

... the following error occurs:

Message: Unable to process binding "enable: function(){return isValid() }"
Message: isValid is not defined
    at enable (eval at createBindingsStringEvaluator (knockout-3.4.2.debug.js:2992), <anonymous>:3:59)
    at update (knockout-3.4.2.debug.js:4211)
    at ko.dependentObservable.disposeWhenNodeIsRemoved (knockout-3.4.2.debug.js:3383)
    at Function.evaluateImmediate_CallReadThenEndDependencyDetection (knockout-3.4.2.debug.js:2183)
    at Function.evaluateImmediate_CallReadWithDependencyDetection (knockout-3.4.2.debug.js:2150)
    at Function.evaluateImmediate (knockout-3.4.2.debug.js:2111)
    at Object.ko.computed.ko.dependentObservable (knockout-3.4.2.debug.js:1964)
    at knockout-3.4.2.debug.js:3381
    at Object.arrayForEach (knockout-3.4.2.debug.js:159)
    at applyBindingsToNodeInternal (knockout-3.4.2.debug.js:3353)

Basically I do this (heavily reduced code):

model.new = new MyModel();
ko.validatedObservable(model.new);
ko.applyBindings(model);

I also tried it like this, but the same error occurs:

model.new = ko.validatedObservable(new MyModel());
ko.applyBindings(model);

The strange thing is that if I change the button binding as follows, the error is gone, but the button remains disabled even if my model becomes valid:

<button data-bind="enable: $parent.new.isValid, click: submit">Submit</button>

I also checked in the console and executing model.new.isValid() there throws the error "Uncaught TypeError: model.new.isValid is not a function".

I guess something must have changed in either Knockout or Knockout validation but I can't find what could be wrong here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions