You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using a ViewModel with a nested underlying observable Model, both of which are instantiated at runtime before bindings are applied. In short, the underlying model, if ever found to be invalid, will never validate correctly. I'm using ko.validation.group to perform the validation (perhaps this is a bad practice?), invoked from the ViewModel on the Model. The result's errors array includes a first-level error of null; the observable that generates this is the Model itself.
I found that by changing if (!observable.isValid()) { to if (!observable.isValid() && observable.error) { (lines /Src/knockout.validation.js:250,263) works around the issue, but I'm not certain this is the right approach. It's also possible I should be doing something differently in the first place (such as not using ko.validation.group directly).
I have created (and will attach) a test to demonstrate, as well as a patch for knockout.validation.js.
An additional thing I noticed while building the test is that the underlying model never appears to be a validatable (uncommenting // ok(vm._model.isValid, 'Underlying model should be validatable'); in the test will cause it to fail). Again, am unsure if this is relevant or important.
The text was updated successfully, but these errors were encountered:
I had same problem, nested observables with validation. So the one magic:
in self.errors = ko.validation.group(self.submissionAnswers, { deep: true, live: true });
pay attention on special additional param: object that contains field live: true
May be related to https://github.com/ericmbarnard/Knockout-Validation/issues/99.
I am using a ViewModel with a nested underlying observable Model, both of which are instantiated at runtime before bindings are applied. In short, the underlying model, if ever found to be invalid, will never validate correctly. I'm using
ko.validation.group
to perform the validation (perhaps this is a bad practice?), invoked from the ViewModel on the Model. The result's errors array includes a first-level error ofnull
; the observable that generates this is the Model itself.I found that by changing
if (!observable.isValid()) {
toif (!observable.isValid() && observable.error) {
(lines /Src/knockout.validation.js:250,263) works around the issue, but I'm not certain this is the right approach. It's also possible I should be doing something differently in the first place (such as not usingko.validation.group
directly).I have created (and will attach) a test to demonstrate, as well as a patch for knockout.validation.js.
An additional thing I noticed while building the test is that the underlying model never appears to be a validatable (uncommenting
// ok(vm._model.isValid, 'Underlying model should be validatable');
in the test will cause it to fail). Again, am unsure if this is relevant or important.The text was updated successfully, but these errors were encountered: