Knockout-Contrib / Knockout-Contrib/Knockout-Validation
can't bind to a validatedObservable as the root
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 366
- PR merge metrics
- No merged PRs in 30d
Description
i'm trying to do validation across an entire VM and have been running into problems somewhat like the guy @ http://stackoverflow.com/questions/13364788/knockout-validation-validatedobservable-group-error did. He found a solution to his problem @ http://jsfiddle.net/CGuW2/6/ but it seems flawed to me because he is doing roughly this:
``` javascript
var viewModel = {
num1: ko.observable("50").extend({ number: true, min: 0, max: 100 }),
num2: ko.observable("50").extend({ number: true, min: 0, max: 100 })
};
viewModel.isValidSum = ko.validatedObservable({
num1: viewModel.num1,
num2: viewModel.num2
}).extend({ mustEqual: 100 });
ko.applyBindings(viewModel);
```
Seemed weird that the VM had a property that was the VM only observed...and reading the answer at https://github.com/ericmbarnard/Knockout-Validation/issues/41 i thought something like this would be the "right" answer:
``` javascript
var viewModel = {
num1: ko.observable("50").extend({ number: true, min: 0, max: 100 }),
num2: ko.observable("50").extend({ number: true, min: 0, max: 100 })
};
var vm = ko.validatedObservable(viewModel).extend({ mustEqual: 101 });
ko.applyBindings(vm);
```
But when i use this with a tweaked View (see http://jsfiddle.net/drdamour/5B8s4/ ) the validation of the individual input boxes works, but the error property can't be bound to, although it is there, verified by a console.log.
Not being able to use a validatedObservable as a root VM seems like a bug that isn't intended. Is it intended that you can use extend on a validatedObservable to do VM level validation?
Contributor guide
Research direction
Reproduce the validatedObservable-as-root case from the issue and compare it with the linked jsFiddle examples. Trace how the root observable is exposed to bindings, then confirm that VM-level validation errors can be bound while individual input validation continues to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100