Knockout-Contrib / Knockout-Contrib/Knockout-Validation

Validating observableArray objects with validatedObservable

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

Description

I have a parent object with an observable array that may or may not have objects in it (these can be added by the user) and each of the objects within the array has it's own validation. I'd like to set up the validation on the parent object so that it will be marked as invalid if any of the objects within it's observable array are invalid. To do this I'd like to set up a validatedObservable on each child object with a validatedObservable in the parent that references the observableArray since this seems the common sense approach. However, no matter what I do with the validatedObservables and whatever options I use to configure (deep and live both being true seem like the most likely to work) I still can't get the parent validatedObservable to respond to invalid states within the child objects.

I've set up a simple example at the follow fiddle:
http://jsfiddle.net/3txv0p60/9/

I'd expect this to start as valid (since the observable array is empty and so doesn't contain any invalid objects) and to become invalid as soon as a child object is created but I can never get it to become invalid.

I'm not sure if this is a bug, an unsupported feature or just something in the documentation that I'm not understanding but I'd really appreciate it if someone can point me in the right direction to get this working. Previously I've worked around this using a computed observable that checks the state of each entry in the observable array but I'm hopeful there will be a better solution.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the behavior in the linked JSFiddle, focusing on the parent validatedObservable, child validatedObservables, and observableArray. Check whether deep and live options are intended to propagate child validation state; done means confirming the supported behavior and documenting or correcting the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.