Passing field props via schema
- Zod
- JSON Schema
- Simple Schema
import { AutoForm } from 'uniforms-antd'; import { ZodBridge } from 'uniforms-bridge-zod'; import { z } from 'zod'; enum Role { Member = 'Member', Staff = 'Staff', } const userSchema = z.object({ username: z.string(), password: z.string().uniforms({ type: 'password' }), role: z.nativeEnum(Role).uniforms({ checkboxes: true }), }); const schema = new ZodBridge({ schema: userSchema }); export default function App() { return ( <AutoForm schema={schema} onSubmit={model => window.alert(JSON.stringify(model))} /> ); }
import { AutoForm } from 'uniforms-antd'; import { schema } from './userSchema'; export default function App() { return ( <AutoForm schema={schema} onSubmit={model => window.alert(JSON.stringify(model))} /> ); }
import { AutoForm } from 'uniforms-antd'; import { SimpleSchema2Bridge } from 'uniforms-bridge-simple-schema-2'; import SimpleSchema from 'simpl-schema'; enum Role { Member = 'Member', Staff = 'Staff', } const userSchema = new SimpleSchema({ username: String, password: { type: String, uniforms: { type: 'password' } }, role: { type: String, allowedValues: [Role.Member, Role.Staff], uniforms: { checkboxes: true }, }, }); const schema = new SimpleSchema2Bridge({ schema: userSchema }); export default function App() { return ( <AutoForm schema={schema} onSubmit={model => window.alert(JSON.stringify(model))} /> ); }