Skip to content

Commit 3e57f9e

Browse files
MeAkibAndrewKushnir
authored andcommitted
docs: add documentation for schema validation with Signal Forms
Fixes: angular#66098
1 parent 7335b98 commit 3e57f9e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

adev/src/content/guide/forms/signals/validation.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,26 @@ While async validation runs, the field's `pending()` signal returns `true`. Use
658658

659659
The `valid()` signal returns `false` while validation is pending, even if there are no errors yet. The `invalid()` signal only returns `true` if errors exist.
660660

661+
## Integration with schema validation libraries
662+
663+
Signal Forms have built-in support for libraries that conform to [Standard Schema](https://standardschema.dev/) like [Zod](https://zod.dev/) or [Valibot](https://www.validbot.com/). The integration is provided via the `validateStandardSchema` function. This allows you to use existing schemas while maintaining Signal Forms' reactive validation benefits.
664+
665+
```ts
666+
import {form, validateStandardSchema} from '@angular/forms/signals';
667+
import * as z from 'zod';
668+
669+
// Define your schema
670+
const userSchema = z.object({
671+
email: z.email(),
672+
password: z.string().min(8),
673+
});
674+
675+
// Use with Signal Forms
676+
const userForm = form(signal({email: '', password: ''}), (schemaPath) => {
677+
validateStandardSchema(schemaPath, userSchema);
678+
});
679+
```
680+
661681
## Next steps
662682

663683
This guide covered creating and applying validation rules. Related guides explore other aspects of Signal Forms:

0 commit comments

Comments
 (0)