Knockout-Contrib / Knockout-Contrib/Knockout-Validation
Validation on nested objects not working after changing whole object
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 366
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior using the two linked JSFiddles, focusing on changePerson and the person().firstName binding. Compare it with the ko with person workaround; done means validation messages still appear after replacing the whole person object without requiring that workaround.
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