-
-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Validation): Add validation-object-errors binding (with new propertyNames parameter for ensureObject().satisfies()) #351
Comments
@dkent600 sounds like there's two parts to this.
|
Minor correction (see .bind):
Otherwise that looks good. To reiterate: this would change the behavior of the
I propose this would work by adding a parameter to The (Side note: I note that the
By "ensureProperty" do you mean "ensure"? I'm not familiar with "ensureProperty". I assume you mean "ensure" (and perhaps are thinking of renaming it?). In any case, I'm not really clear about this question in general. My entire use case is based on validating the entire object. It seems like property-based validation is working pretty well in the context of this feature request. Are you thinking there is an improvement here that I haven't thought of?
Yes, it is exactly this (ie, part 2. of your question). Good idea to put this all together in one place. |
A corrolary of this could be that when one calls:
then all associated rules that reference the property would be evaluated. This would include object-level rules where the names of the implicated properties will have been given in the new version of |
There might be a cleaner way of triggering validation of a whole object when any input is changed, blurred or both, depending on the behavior you're going for. <style>
.has-error > input {
border-color: red;
}
</style>
<form blur.capture="controller.validate({ object: person })"
change.delegate="controller.validate({ object: person })"
input.delegate="controller.validate({ object: person })"
style.bind="controller.errors.length ? 'has-error' : ''">
<input value.bind="person.firstName">
<input value.bind="person.lastName">
</form> |
@jdanyow Hmmm, honestly, that doesn't look cleaner to me than simply adding Further, it adds nothing without the enhancement to I think that with the changes I've proposed here, it would move object-level validation closer to, if not on par with, the existing property-level support. |
I was thinking you'd only be using one of the It's true this doesn't do anything with the property names stuff you mentioned. I need to get on the same page with you on this part. It would be extremely helpful if you could share some more user-story / concrete use-case kind of information so I can visualize how this is supposed to work. Even better if you could put together a gist with real class names, property names, rules, actual UI layout, etc, that I would be able to use when testing out implementation changes that attempt to meet the need. |
I'll see what I can do! BTW, I can't for the life of me find a reference to "blur.capture". What is that? (I know what blur is, but a |
whoops- capture is a new binding command- I'm just realizing it's not even released yet (or documented yet: aurelia/binding#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 |
In reference to the Gist found here: https://gist.run/?id=7103145949f2b899337a635ff6b8ca74 First, I would like to enumerate the problems I see with using something like
In the Gist, you can see the following
I hope this helps! |
I think I now understand that there is an asymmetry in my proposal between My main concern in this comment, however, is whether forcing object-level validation would actually be feasible for Maybe it would make more sense to add a new option on the |
Criteria for acceptance:
|
@dkent600 thanks for all your work here fleshing this out- the one thing I was really hoping to get was an actual use case. Something we could put in the docs for this. I don't think the first name "abc" thing fits the bill. I really want a get something that people can relate to because it will make the docs understandable. Not to mention it will allow me to wrap my head around what the need is and hopefully come up with a good implementation with the least amount of boilerplate. |
@jdanyow Thanks for your patience on this. Ok, how does this do: Case 1 You are using So when displaying validation errors you want to give feedback as to which GUI elements are complicit in breaking rules defined by Case 2 In addition to case 1, you are displaying a set of objects, each as a row in a table in your GUI. You are using a single validation controller to validate all of them, but validating one object at-a-time (it would be quite inefficient and awkward to use a separate validation controller for each object). So when displaying validation errors pertaining to a specific row/object, you want to include messages from failed rules defined by Case 3 In addition to either case 1 or case 2, you are saving changes to the entire object whenever the user makes a valid modification to a property, without requiring that the GUI include a "Save Changes" button. So you want the validateTrigger to cause object-level rather property-level validation |
Man, I've really made a mess of this. Thanks for your patience! With some more work I've narrowed this down much more cleanly. First, please refer to a new gist, here. The fundamental issue: Rules defined by
In both of the above cases a property can appear to be valid when in fact it is not. The gist demonstrates these two issues in two separate use cases. To address this I propose adding a (This was the original request. I think we can scrap the suggestion about a new |
Just a post mortem comment: This resolution does leave hanging one feature I had requested here, that is, the ability to force automatic, full object-level validation, either by configuration in the HTML or the JavaScript API. As it stands now the user is always required to manually write code to execute an object-level validation. I abandonned that idea when I realized that much (all?) of the need for such a feature would be addressed with the proposed change to But I would not want to foreclose the possibility of this coming up again. If nothing else, just in terms of conceptual symmetry and elegance, it seems like a hole in the functionality. We'll see how it goes.... |
Similar to my last comment just above (the ability to force automatic, full object-level validation), I think is this one #349 |
In a recent comment above, I described the following two cases, both of which I've solved using the existing Aurelia validation api:
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 |
Proposed Change
I have previously proposed adding a
propertyNames
parameter toensureObject().satisfies()
(see here) and here.Further to that, I here propose the following:
Create a new binding like
validation-errors
calledvalidation-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.(#279 (comment)) 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 withensure().satisfies()
it is not possible to associateensureObject().satisfies()
with a property name, much less with multiple property names.Further, I am using neither the
validate
binding nor aValidationRenderer
. Again, I am manually callingValidationController.validate()
, and manually rendering the error information whenvalidate
completes.A ValidationRenderer could be useful for me in this scenario, but it is not, for the following reasons:
validate
binding, it does not provide the element(s) with which a property is associated.ensureObject().satisfies()
The text was updated successfully, but these errors were encountered: