MrBr / antd-zod

Antd Zod validation
MIT License
30 stars 6 forks source link

Does the library support validate File? #13

Open minhchi1509 opened 5 days ago

minhchi1509 commented 5 days ago

Can you give more example about validating file (file type, file size, max number of files,...)?

MrBr commented 5 days ago

It should be working if described properly with Zod schema, haven't tried it though. Did you try to define file as zod schema?

Something like:

const fileSchema = zod.object({
  name: z.string(),
  size: z.number().max(1000),
  type: z.enum(["image/png", "image/jpeg"]);
});

const formSchema = z.object({
  files: zod.array(fileSchema)
})

const formRule = createSchemaFieldRule(
  formSchema
);

Later in the Form:

          <FormItem
            name="files"
            rules={[formRule]}
          >
            <Input />
          </FormItem>