Knockout-Validation icon indicating copy to clipboard operation
Knockout-Validation copied to clipboard

Controlled "deep" validation + observed find children

Open lcorneliussen opened this issue 11 years ago • 3 comments

I have a couple of problems with the current validation engine:

  • I have circular references in my view model, so deep never ends.
  • I have a list of objects from which one can be chosen; only the chosen one should get validated
  • Since choosing the object (by setting an observable to one of the lists objects) the elements to validate in a group change - so it is not enough to just collect once...

I have a draft locally which fixes the first to problems by explicitly telling ko.validation which path to follow when validating. Currently this is done by extending with { followOnValidation: true }.

It will then also subscribe to those extended objects and update the "validatables" for the group correspondingly.

What do you think of that approach?

lcorneliussen avatar Aug 29 '12 10:08 lcorneliussen

@lcorneliussen

I'm interested - but not sure I'm grasping what you're trying to describe without seeing it.

I've had on my list of "TODOs" for while to take a deeper look at the traverse logic on the group function. It would be relatively easy to add some more intelligence to that in the form of:

  1. keeping a hasVisited array and checking each node against that before walking it
  2. surrounding some of the walking with more try/catch handlers in case things go awry
  3. Pulling the traverse function out into a named function separate from the group function so that we can write tests on it

Those were my ideas - any interest on blending the 2?

ericmbarnard avatar Aug 29 '12 19:08 ericmbarnard

https://github.com/faktumsoftware/Knockout-Validation/commit/614f15a86d7b0913ae45c0f03810e262bdce7882

I don't like my approach, but it works for me now.... Would you have a look at it?

Approach is to keep a list of children pr. "node" in the validation tree... Then combine those lists using ko.computed - on the root...

lcorneliussen avatar Aug 30 '12 10:08 lcorneliussen

I have a simple solution for deep validation knockout, may be can help you. https://github.com/Hernandesjunio/KnockoutModelChainValidation

Hernandesjunio avatar Apr 25 '16 20:04 Hernandesjunio