Skip to main content

Passing field props via 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))}
    />
  );
}