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:
Matthieu Riegler 2025-11-17 00:00:14 +01:00 committed by Jessica Janiuk
parent f47637426f
commit b41a94bc85
2 changed files with 16 additions and 1 deletions

View file

@ -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);
}

View file

@ -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');
});
});