Skip to content

Commit 91d8d55

Browse files
JeanMechethePunderWoman
authored andcommitted
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 (cherry picked from commit b41a94b)
1 parent 6aa4b7e commit 91d8d55

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

packages/forms/signals/src/api/validators/standard_schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,5 @@ function standardIssueToFormTreeError(
121121
const pathKey = typeof pathPart === 'object' ? pathPart.key : pathPart;
122122
target = target[pathKey] as FieldTree<Record<PropertyKey, unknown>>;
123123
}
124-
return addDefaultField(standardSchemaError(issue), target);
124+
return addDefaultField(standardSchemaError(issue, {message: issue.message}), target);
125125
}

packages/forms/signals/test/node/api/validators/standard_schema.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,19 @@ describe('standard schema integration', () => {
194194

195195
expect(f().errors().length).toBe(1);
196196
});
197+
198+
it('should set the error message from the schema issue', () => {
199+
const model = signal({age: -5});
200+
const f = form(
201+
model,
202+
(p) => {
203+
validateStandardSchema(p.age, z.number().min(0, {message: 'Age must be non-negative'}));
204+
},
205+
{
206+
injector: TestBed.inject(Injector),
207+
},
208+
);
209+
210+
expect(f.age().errors()[0].message).toBe('Age must be non-negative');
211+
});
197212
});

0 commit comments

Comments
 (0)