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

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()

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

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

@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.

whoops- capture is a new binding command- I’m just realizing it’s not even released yet (or documented yet: https://github.com/aurelia/binding/issues/538).

What it does is enable you to use event delegation for events that do not bubble upwards (like blur) by subscribing to their “capture” phase. Check out “useCapture” here for more info.

Capture example you can experiment with: https://gist.run/?id=196c99652a28d571527a8fff63297308 Capture issue in binding: https://github.com/aurelia/binding/pull/530