question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat(Validation): Add validation-object-errors binding (with new propertyNames parameter for ensureObject().satisfies())

See original GitHub issue

Proposed Change

I have previously proposed adding a propertyNames parameter to ensureObject().satisfies() (see here) and here.

Further to that, I here propose the following:

Create a new binding like validation-errors called validation-object-errors for instance-level (rather than property-level) validation.

This new binding would have the following effects:

  1. it would change behavior of the inner validate binding by causing whole object to be validated on each property change (rather than a single modified property).

  2. in the ValidationRenderer, RenderInstruction would be filled-in with elements and property names for all the rules that have failed. (Again, see my earlier proposal and here.

(https://github.com/aurelia/validation/issues/279#issuecomment-250188672) that would come in quite handy here).

Use Case

My form contains a table of rows, each of which displays an object instance that has been added to the controller for validation.

I am validating at the object level, thus must manually call ValidationController.validate(). I want to display validation errors separately for each row and thus want an easy way to identify errors associated with each object.

Each object contains object rules (defined by ensureObject().satisfies()). These object rules do not depend on other rules, but they do relate to a set of properties on the object. However, unlike with ensure().satisfies() it is not possible to associate ensureObject().satisfies() with a property name, much less with multiple property names.

Further, I am using neither the validate binding nor a ValidationRenderer. Again, I am manually calling ValidationController.validate(), and manually rendering the error information when validate completes.

A ValidationRenderer could be useful for me in this scenario, but it is not, for the following reasons:

  1. without using the validate binding, it does not provide the element(s) with which a property is associated.
  2. it provides neither property names nor elements for rules define by ensureObject().satisfies()

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
dkent600commented, Jan 27, 2017

In a recent comment above, I described the following two cases, both of which I’ve solved using the existing Aurelia validation api:

  1. Validation messages from rules defined in ensureObject().satisfies() are never associated with a GUI element and thus cannot be rendered to the user via the ValidationRenderer mechanism.

  2. The validate value converter, when a validation is triggered on an associated property, never triggers the evaluation of rules defined by ensureObject().satisfies().

Each of these use cases is solved by defining the rule as a named custom rule, and applying the rule to the properties that depend on it.

This is demonstrated in the following gist: https://gist.run/?id=37835cb9165093a1c2deb2ea8113e287

1reaction
jdanyowcommented, Dec 30, 2016

@dkent600 no worries! I’ll close this one out and we can continue tracking/discussing a mechanism for expressing a rule’s property dependencies in #279.

Thanks for sticking with this one. I’ll add your gist to #279.

Read more comments on GitHub >

github_iconTop Results From Across the Web

aurelia/validation - Gitter
Now, if I had value.bind on these, calling controller.validate() would work. But now I have to use addObject() : this.controller.addObject( ...
Read more >
Validation | Aurelia
This article covers the basics of validation with Aurelia's validation plugin. You'll learn how to add validation to your applications using a fluent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found