Move from ValidationErrorResult to HttpBadRequest, and support object-level errors too

This commit is contained in:
SteveSandersonMS
2015-12-14 12:02:41 +00:00
parent bba388944d
commit 8a148d8535
6 changed files with 72 additions and 39 deletions

View File

@@ -14,16 +14,19 @@ export class Validation {
var errors = <ValidationErrorResult>response;
Object.keys(errors || {}).forEach(key => {
errors[key].forEach(errorMessage => {
// This in particular is rough
if (!controlGroup.controls[key].errors) {
(<any>controlGroup.controls[key])._errors = {};
// If there's a specific control for this key, then use it. Otherwise associate the error
// with the whole control group.
var control = controlGroup.controls[key] || controlGroup;
// This is rough. Need to find out if there's a better way, or if this is even supported.
if (!control.errors) {
(<any>control)._errors = {};
}
controlGroup.controls[key].errors[errorMessage] = true;
control.errors[errorMessage] = true;
});
});
}
}
export interface ValidationErrorResult {