Knockout-Contrib / Knockout-Contrib/Knockout-Validation

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

Open
#661 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1k
Forks
366
PR merge metrics
No merged PRs in 30d

Description

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


....
Submit // or isValid()

... 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), :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:

Submit

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.

Contributor guide

Open the contributing guide

Research direction

Start with the reduced MyModel setup and the ko.validatedObservable calls shown in the issue, then reproduce the enable binding error using Knockout 3.4.2 and Knockout.Validation 2.0.3. Compare the binding context for isValid with the model.new.isValid lookup and verify the expected observable shape. Done means the existing binding works without an undefined-property or non-function error and the button responds when validation changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.