Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation on nested objects not working after changing whole object #398

Open
skwasiborski opened this issue Jan 28, 2014 · 2 comments
Open
Milestone

Comments

@skwasiborski
Copy link

Hi, I have a problem with validating nested objects.
I have following view model:

      var ViewModel = function (first) {
           this.person = ko.observable(new Person(first));

           this.changePerson = function () {
               this.person(new Person("changed"));
           };
      };

      var Person = function (first) {
           this.firstName = ko.observable(first).extend({
                required: true
           });
      };

everything works as expected as long as I do not call changePerson function. After calling change if I have element with data-bind="person().firstName" validation messages will not show. Working example (http://jsfiddle.net/MDhUR/). I found a work round to this issue - if I use to bind to firstName everything works as expected (http://jsfiddle.net/seRr5/1/) .

regards.

@crissdev
Copy link
Member

@skwasiborski I've updated your fiddle to make it work - I manually inserted the validation message element. I'll look into this to see where the problem is. Until then, here's the updated fiddle

@maksimbykov
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants