Knockout-Validation
Knockout-Validation copied to clipboard
Controlled "deep" validation + observed find children
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
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:
- keeping a
hasVisited
array and checking each node against that before walking it - surrounding some of the walking with more
try/catch
handlers in case things go awry - Pulling the
traverse
function out into a named function separate from thegroup
function so that we can write tests on it
Those were my ideas - any interest on blending the 2?
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...
I have a simple solution for deep validation knockout, may be can help you. https://github.com/Hernandesjunio/KnockoutModelChainValidation