Skip to content
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

API to add/remove errors #261

Closed
jods4 opened this issue Jun 20, 2016 · 6 comments
Closed

API to add/remove errors #261

jods4 opened this issue Jun 20, 2016 · 6 comments

Comments

@jods4
Copy link
Contributor

jods4 commented Jun 20, 2016

It would be nice to have some kind of addError() and removeError() API on the validation controller.

Use cases:

  • A value converter, binding behavior or custom binding wants to report an error in the form.
    For example, your model contains a contact: Person property and you use a custom control to pick a Person class by its name. Imagine the user types an incorrect name. Short of considering undefined an error signal, this is hard to detect on the model alone.
  • You want to display server-sent errors on the UI.
    For example, you tried to save but the server returned a unique key violation on the name of your entity (note: async validation can't cover this use case in the face of concurrency... you may add async valdiation or not, but you should always be ready to handle failure at commit time.) It would be nice to be able to map this error back to the name field in the UI.
  • You want to define errors for things that are not UI-driven.
@andrewharry
Copy link

I agree that it is nicer if server side issues can highlight the relevant input field. A simple extension to the validation controller would be ideal.

@jdanyow
Copy link
Contributor

jdanyow commented Jun 21, 2016

We're definitely going to add this. It supports a very common validation pattern where simple rules are validated synchronously, data is submitted to the server and if the server returns errors, they can be rendered in the UI- basic async validation.

@y2k4life
Copy link
Contributor

y2k4life commented Jun 21, 2016

My question with this is how to know the target? There is is a method currently _updateErrors(errors, newErrors, target) in the ValidationController. Is the idea with addError and removeError to update the View as well? I have a situation where I have a form with header input and a detail input. There is an overall submit form button, but there is also a sub form for adding items with a Add Item button. When addItem is invoked I want to validate just the item details/object of the sub form. I see that Validator has validateObject which could validate the object of the subform, but that is not tied to the View. I could in theory call _udpateErrors or addError() but how does that tie to the target? If I have an error how would I just display the error message for the inputs of the sub form without updating the whole form? Could there be a ValidateObject on in the ValidationController? The challange I had adding this is that ValidateController is driven from the bindings on the view & validate and this would be driven from the model/object.

When the Add button is clicked how do I validate just Date of Loss, Loss Amount, and Reason of Loss? If I'm able to that and get errors then how would I use addError and how do I target just those fields with error messages?

subform

@jdanyow
Copy link
Contributor

jdanyow commented Jun 21, 2016

How will the target be determined?

The addError method would accept a ValidationError which includes the relevant object and optionally the property name. The controller can use these two pieces of information to locate the relevant binding(s) which in turn will enable it to determine the target element.

How do I validate a single item in my detail grid?

validate() will soon accept an object and optionally a property to enable validating a specific object or property.

@tkhyn
Copy link

tkhyn commented Jul 1, 2016

It would be great to have such a feature. I was looking for ways to do that and landed here.

I would suggest that addError could also support errors that are relevant to the entire form and not to a specific field? For example if the property name (e.g. 'non_field_errors') does not match an existing binding in the controller it still passes the ValidationError to the user-defined validation renderer.

@jdanyow
Copy link
Contributor

jdanyow commented Aug 27, 2016

closing- this was added in friday's release.

@jdanyow jdanyow closed this as completed Aug 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants