feat(Validation): Add validation-object-errors binding (with new propertyNames parameter for ensureObject().satisfies())
See original GitHub issueProposed 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:
-
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).
-
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:
- without using the
validate
binding, it does not provide the element(s) with which a property is associated. - it provides neither property names nor elements for rules define by
ensureObject().satisfies()
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (18 by maintainers)
Top GitHub Comments
In a recent comment above, I described the following two cases, both of which I’ve solved using the existing Aurelia validation api:
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.
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.