mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
fix(forms): Set error message of a schema error.
Use the error message of the issue as the error message of the error itself. fixes #65247
This commit is contained in:
parent
f47637426f
commit
b41a94bc85
2 changed files with 16 additions and 1 deletions
|
|
@ -121,5 +121,5 @@ function standardIssueToFormTreeError(
|
|||
const pathKey = typeof pathPart === 'object' ? pathPart.key : pathPart;
|
||||
target = target[pathKey] as FieldTree<Record<PropertyKey, unknown>>;
|
||||
}
|
||||
return addDefaultField(standardSchemaError(issue), target);
|
||||
return addDefaultField(standardSchemaError(issue, {message: issue.message}), target);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,4 +194,19 @@ describe('standard schema integration', () => {
|
|||
|
||||
expect(f().errors().length).toBe(1);
|
||||
});
|
||||
|
||||
it('should set the error message from the schema issue', () => {
|
||||
const model = signal({age: -5});
|
||||
const f = form(
|
||||
model,
|
||||
(p) => {
|
||||
validateStandardSchema(p.age, z.number().min(0, {message: 'Age must be non-negative'}));
|
||||
},
|
||||
{
|
||||
injector: TestBed.inject(Injector),
|
||||
},
|
||||
);
|
||||
|
||||
expect(f.age().errors()[0].message).toBe('Age must be non-negative');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue