vue-formic-dynamic-forms
Version:
Powerful library for creating dynamic, validated forms in Vue 3 based on JSON schemas
120 lines (95 loc) • 2.53 kB
Markdown
//badge.fury.io/js/vue-dynamic-forms.svg)](https://badge.fury.io/js/vue-dynamic-forms)
[](https://opensource.org/licenses/MIT)
Powerful library for creating dynamic, validated forms in Vue 3 based on JSON schemas.
🎯 **Declarative JSON Schemas** - Define forms using JSON configuration
🎨 **Highly Customizable** - Slots for every form element, UI library integration
✅ **Built-in Validation** - Integration with yup, zod, vee-validate
🔀 **Conditional Logic** - Dynamic field visibility based on form values
📘 **TypeScript Support** - Full type safety out of the box
🪶 **Zero Dependencies** - Only Vue 3 as peer dependency
🧩 **Composable Architecture** - Use composables in any component structure
```bash
npm install vue-dynamic-forms
pnpm add vue-dynamic-forms
yarn add vue-dynamic-forms
```
```typescript
import { createApp } from 'vue'
import VueDynamicForms from 'vue-dynamic-forms'
import 'vue-dynamic-forms/style.css'
import App from './App.vue'
const app = createApp(App)
app.use(VueDynamicForms)
app.mount('#app')
```
```vue
<template>
<DynamicForm :schema="formSchema" @submit="onSubmit" />
</template>
<script setup lang="ts">
import type { FormSchema } from 'vue-dynamic-forms'
const formSchema: FormSchema = {
fields: [
{
name: 'email',
type: 'email',
label: 'Email',
validation: { required: true, email: true }
},
{
name: 'password',
type: 'password',
label: 'Password',
validation: { required: true, minLength: 6 }
}
]
}
</script>
```
```typescript
{
name: 'jobDetails',
type: 'text',
label: 'Job Details',
conditions: {
show: [{ field: 'hasJob', operator: 'equals', value: true }]
}
}
```
```typescript
{
name: 'username',
type: 'text',
validation: {
custom: (value, formData) => {
return value.length >= 3 || 'Username must be at least 3 characters'
}
}
}
```
```vue
<script setup>
import { useDynamicForm } from 'vue-dynamic-forms'
const { formData, validateForm, submitForm } = useDynamicForm({
schema: mySchema
}, {
submit: (data, isValid) => {
// Handle submission
}
})
</script>
```
MIT © [Your Name]
[![npm version](https: