Note that there are some explanatory texts on larger screens.

plurals
  1. POBreeze.js & Knockout.js: translating breeze validation to knockout validation causes an 'Out of stack space' or 'Too much recursion'
    primarykey
    data
    text
    <p>I have a client side model generated by Breeze/OData and I used the code in <a href="https://stackoverflow.com/questions/15635958/mark-fields-not-valid-as-red-with-knockout-durandal">this post</a> to connect it to Knockout validation.</p> <p>It works great for validating individual fields through the <code>isValid()</code> method. However, whenever I try to use <code>ko.validation.group</code> against a Breeze Entity (assume that the knockout validation is configured with <code>{deep: true}</code>), either calling <code>showAllMessages</code>, <code>length</code> or any other method that performs a tree traversal over the object graph, results in an infinite recursion exception at runtime (see <a href="https://github.com/Knockout-Contrib/Knockout-Validation/blob/master/Src/knockout.validation.js" rel="nofollow noreferrer"><code>knockout.validation.js@231-271</code></a>). Depending on the browser can be "Out of stack space" (IE) or "Too much recursion" (Firefox).</p> <p>I think the root cause of the error is that the algorithm inside Knockout Validation does not keep track of the previously visited nodes. All Breeze Entities contain an <code>entityAspect</code> property and the code inside <code>knockout.validation</code> visits all the properties and all its children using depth first, but without remembering the nodes already visited. And because <code>entityAspect</code> contains a reference back to its containing entity, it results in a stack overflow.</p> <pre><code>validate(entity) // Initial call =&gt; validate(entity.entityAspect) // Validate the first property of the root =&gt; validate(entity.entityAspect.entity) // Validate the first property of the child, which points back to the root! </code></pre> <p>So after all this, the question is: <strong>do you know any work around to avoid this behavior?</strong></p> <p>For now, I think I'm just going to use a dirty cheap hack inside <code>knockout.validation</code> to prevent stepping into an <code>entityAspect</code> property, but I'm sure there should be a better way.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload