Skip to content

Zod

Install the necessary packages via package manager:

bash
npm i @vue-formify/zod zod

Import the helper function to convert zod schema for vue-formify specific schema:

vue
<script lang="ts" setup>
import * as zod from 'zod';
import { schemaFromZod } from '@vue-formify/zod';
import { FormifyForm, FormifyInput } from 'vue-formify';

const schemaZod = schemaFromZod(
  zod.object({
    first_name: zod.string().min(1, { message: 'Required' }),
    last_name: zod.string().min(1, { message: 'Required' }),
  })
);

const sendForm = (data) => {
	console.log(data);
};

</script>
<template>
	<FormifyForm :validation-schema="schemaZod" @submit="sendForm">
        <FormifyInput name="first_name" label="First name" />
        <FormifyInput name="last_name" label="Last name" />
    <button>Submit</button>
  </FormifyForm>
</template>