The user wants an advanced form builder in Vue.js with:
- Dynamic field generation
- Validation
This should be a single HTML file with Vue.js included via CDN. I need to create something visually striking and not generic-looking.
Let me plan the features:
- Drag and drop field types to add to form
- Field types: text, email, number, select, checkbox, radio, textarea, date
- Real-time validation
- Ability to configure field properties (label, placeholder, required, validation rules)
- Preview mode to see the form
- Export/JSON output of the form schema
- Responsive design
Design aesthetic:
- I'll go with a technical/developer tool aesthetic
- Dark theme with a sharp accent color (maybe cyan or lime green)
- Use a distinctive font - maybe "Space Grotesk" for headlines and "DM Sans" for UI
- Grid/blueprint-like background pattern
- Clean, functional but not boring
Let me build this:
- Left panel: Available field types (draggable/clickable)
- Center panel: Form canvas where fields are added
- Right panel: Field configuration when a field is selected
- Header: Form name, preview mode toggle, export button
Interactions:
- Click to add fields
- Drag to reorder fields
- Click field to configure
- Live validation preview
- Smooth animations for adding/removing fields
- Tab switching between builder and preview modes
Let me code this up with proper structure and meaningful interactions.
Advanced Vue.js Form Builder
A dynamic form builder with drag-and-drop field generation, real-time validation, and live preview. Features a technical/developer-focused dark theme with sharp cyan accents.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Forge — Advanced Form Builder</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0a0f;
--bg-elevated: #12121a;
--bg-card: #1a1a24;
--fg: #e8e8ed;
--fg-muted: #6b6b7a;
--accent: #00d4aa;
--accent-dim: #00d4aa22;
--border: #2a2a38;
--error: #ff4757;
--warning: #ffa502;
--success: #00d4aa;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
}
.font-mono {
font-family: 'JetBrains Mono', monospace;
}
/* Grid background */
.grid-bg {
background-image:
linear-gradient(var(--border) 1px, transparent 1px),
linear-gradient(90deg, var(--border) 1px, transparent 1px);
background-size: 40px 40px;
background-position: -1px -1px;
}
/* Custom scrollbar */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: var(--bg-elevated);
}
::-webkit-scrollbar-thumb {
background: var(--border);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--fg-muted);
}
/* Animations */
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.animate-slide-up {
animation: slideUp 0.3s ease-out forwards;
}
.animate-fade-in {
animation: fadeIn 0.2s ease-out forwards;
}
.field-item {
animation: slideUp 0.3s ease-out forwards;
}
/* Focus states */
input:focus, textarea:focus, select:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-dim);
}
/* Drag states */
.dragging {
opacity: 0.5;
transform: scale(0.95);
}
.drag-over {
border-color: var(--accent) !important;
background: var(--accent-dim);
}
/* Transitions */
.list-move,
.list-enter-active,
.list-leave-active {
transition: all 0.3s ease;
}
.list-enter-from,
.list-leave-to {
opacity: 0;
transform: translateX(-30px);
}
.list-leave-active {
position: absolute;
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body class="grid-bg">
<div id="app" class="min-h-screen">
<!-- Header -->
<header class="sticky top-0 z-50 border-b backdrop-blur-xl" style="background: rgba(10,10,15,0.9); border-color: var(--border);">
<div class="max-w-screen-2xl mx-auto px-4 py-3 flex items-center justify-between">
<div class="flex items-center gap-4">
<div class="flex items-center gap-2">
<div class="w-8 h-8 rounded-lg flex items-center justify-center" style="background: var(--accent);">
<svg class="w-5 h-5" style="color: var(--bg);" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
</div>
<span class="text-lg font-semibold tracking-tight">Form Forge</span>
</div>
<div class="h-6 w-px" style="background: var(--border);"></div>
<input
v-model="formName"
type="text"
class="bg-transparent border-none text-sm font-medium px-2 py-1 rounded focus:bg-white/5"
style="color: var(--fg-muted);"
placeholder="Untitled Form"
>
</div>
<div class="flex items-center gap-3">
<!-- Mode Toggle -->
<div class="flex rounded-lg p-1" style="background: var(--bg-elevated);">
<button
@click="mode = 'build'"
:class="['px-4 py-1.5 text-sm font-medium rounded-md transition-all', mode === 'build' ? 'text-black' : 'hover:bg-white/5']"
:style="mode === 'build' ? 'background: var(--accent);' : 'color: var(--fg-muted);'"
>
Build
</button>
<button
@click="mode = 'preview'"
:class="['px-4 py-1.5 text-sm font-medium rounded-md transition-all', mode === 'preview' ? 'text-black' : 'hover:bg-white/5']"
:style="mode === 'preview' ? 'background: var(--accent);' : 'color: var(--fg-muted);'"
>
Preview
</button>
</div>
<button
@click="exportSchema"
class="flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg border transition-all hover:bg-white/5"
style="border-color: var(--border); color: var(--fg);"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"/>
</svg>
Export JSON
</button>
</div>
</div>
</header>
<!-- Main Content -->
<main class="max-w-screen-2xl mx-auto px-4 py-6">
<!-- Build Mode -->
<div v-if="mode === 'build'" class="grid grid-cols-12 gap-6">
<!-- Field Types Panel -->
<aside class="col-span-12 lg:col-span-3">
<div class="rounded-xl border p-4 sticky top-24" style="background: var(--bg-card); border-color: var(--border);">
<h3 class="text-xs font-semibold uppercase tracking-wider mb-4" style="color: var(--fg-muted);">Field Types</h3>
<div class="space-y-2">
<div
v-for="fieldType in fieldTypes"
:key="fieldType.type"
@click="addField(fieldType.type)"
class="flex items-center gap-3 p-3 rounded-lg border cursor-grab transition-all hover:border-[var(--accent)] hover:bg-white/5 active:cursor-grabbing"
style="border-color: var(--border);"
draggable="true"
@dragstart="onDragStart($event, fieldType.type)"
>
<div class="w-10 h-10 rounded-lg flex items-center justify-center" :style="`background: ${fieldType.color}22; color: ${fieldType.color};`">
<span v-html="fieldType.icon"></span>
</div>
<div>
<div class="text-sm font-medium">{{ fieldType.label }}</div>
<div class="text-xs" style="color: var(--fg-muted);">{{ fieldType.description }}</div>
</div>
</div>
</div>
</div>
</aside>
<!-- Form Canvas -->
<div class="col-span-12 lg:col-span-5">
<div
class="rounded-xl border min-h-[600px] p-6 transition-all"
:class="isDragOver ? 'drag-over' : ''"
style="background: var(--bg-card); border-color: var(--border);"
@dragover.prevent="isDragOver = true"
@dragleave="isDragOver = false"
@drop="onDrop"
>
<div v-if="fields.length === 0" class="h-full flex flex-col items-center justify-center py-20">
<div class="w-16 h-16 rounded-2xl flex items-center justify-center mb-4" style="background: var(--bg-elevated);">
<svg class="w-8 h-8" style="color: var(--fg-muted);" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
</svg>
</div>
<p class="text-sm font-medium mb-1" style="color: var(--fg-muted);">No fields yet</p>
<p class="text-xs" style="color: var(--fg-muted);">Click or drag fields from the left panel</p>
</div>
<TransitionGroup v-else name="list" tag="div" class="space-y-3">
<div
v-for="(field, index) in fields"
:key="field.id"
@click="selectField(field)"
class="field-item group relative rounded-lg border p-4 cursor-pointer transition-all"
:style="selectedField?.id === field.id ? 'border-color: var(--accent); background: var(--accent-dim);' : 'border-color: var(--border);'"
draggable="true"
@dragstart="onFieldDragStart($event, index)"
@dragover.prevent="onFieldDragOver($event, index)"
@drop="onFieldDrop($event, index)"
@dragend="onFieldDragEnd"
>
<!-- Field Header -->
<div class="flex items-center justify-between mb-3">
<div class="flex items-center gap-2">
<span class="text-xs font-mono px-2 py-0.5 rounded" style="background: var(--bg-elevated); color: var(--fg-muted);">{{ index + 1 }}</span>
<span class="text-sm font-medium">{{ field.label || 'Untitled Field' }}</span>
<span v-if="field.required" class="text-xs px-1.5 py-0.5 rounded" style="background: var(--error)22; color: var(--error);">Required</span>
</div>
<div class="flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
<button @click.stop="duplicateField(index)" class="p-1.5 rounded hover:bg-white/10" title="Duplicate">
<svg class="w-4 h-4" style="color: var(--fg-muted);" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
</button>
<button @click.stop="removeField(index)" class="p-1.5 rounded hover:bg-white/10" title="Delete">
<svg class="w-4 h-4" style="color: var(--error);" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</svg>
</button>
</div>
</div>
<!-- Field Preview -->
<div class="pointer-events-none">
<FieldPreview :field="field" />
</div>
</div>
</TransitionGroup>
</div>
</div>
<!-- Field Settings Panel -->
<aside class="col-span-12 lg:col-span-4">
<div v-if="selectedField" class="rounded-xl border p-5 sticky top-24" style="background: var(--bg-card); border-color: var(--border);">
<div class="flex items-center justify-between mb-6">
<h3 class="text-sm font-semibold">Field Settings</h3>
<span class="text-xs font-mono px-2 py-1 rounded" style="background: var(--bg-elevated); color: var(--fg-muted);">{{ selectedField.type }}</span>
</div>
<div class="space-y-5">
<!-- Label -->
<div>
<label class="block text-xs font-medium mb-2" style="color: var(--fg-muted);">Label</label>
<input
v-model="selectedField.label"
type="text"
class="w-full px-3 py-2 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
placeholder="Field label"
>
</div>
<!-- Placeholder -->
<div v-if="['text', 'email', 'number', 'textarea', 'tel', 'url'].includes(selectedField.type)">
<label class="block text-xs font-medium mb-2" style="color: var(--fg-muted);">Placeholder</label>
<input
v-model="selectedField.placeholder"
type="text"
class="w-full px-3 py-2 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
placeholder="Enter placeholder text"
>
</div>
<!-- Help Text -->
<div>
<label class="block text-xs font-medium mb-2" style="color: var(--fg-muted);">Help Text</label>
<input
v-model="selectedField.helpText"
type="text"
class="w-full px-3 py-2 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
placeholder="Optional helper text"
>
</div>
<!-- Options for select/radio/checkbox -->
<div v-if="['select', 'radio', 'checkbox'].includes(selectedField.type)">
<label class="block text-xs font-medium mb-2" style="color: var(--fg-muted);">Options</label>
<div class="space-y-2">
<div v-for="(option, optIndex) in selectedField.options" :key="optIndex" class="flex gap-2">
<input
v-model="option.value"
type="text"
class="flex-1 px-3 py-2 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
>
<button @click="removeOption(optIndex)" class="p-2 rounded-lg border hover:bg-white/5" style="border-color: var(--border);">
<svg class="w-4 h-4" style="color: var(--error);" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
</svg>
</button>
</div>
<button
@click="addOption"
class="w-full px-3 py-2 rounded-lg border text-sm transition-all hover:bg-white/5"
style="border-color: var(--border); color: var(--fg-muted); border-style: dashed;"
>
+ Add Option
</button>
</div>
</div>
<!-- Validation Rules -->
<div class="pt-4 border-t" style="border-color: var(--border);">
<h4 class="text-xs font-semibold uppercase tracking-wider mb-4" style="color: var(--fg-muted);">Validation</h4>
<div class="space-y-4">
<!-- Required -->
<label class="flex items-center justify-between cursor-pointer">
<span class="text-sm">Required Field</span>
<button
@click="selectedField.required = !selectedField.required"
class="w-11 h-6 rounded-full transition-all relative"
:style="selectedField.required ? 'background: var(--accent);' : 'background: var(--bg-elevated);'"
>
<span
class="absolute top-1 w-4 h-4 rounded-full transition-all"
:style="selectedField.required ? 'left: 26px; background: var(--bg);' : 'left: 4px; background: var(--fg-muted);'"
></span>
</button>
</label>
<!-- Min/Max for text -->
<div v-if="['text', 'textarea', 'email', 'tel', 'url'].includes(selectedField.type)" class="grid grid-cols-2 gap-3">
<div>
<label class="block text-xs font-medium mb-2" style="color: var(--fg-muted);">Min Length</label>
<input
v-model.number="selectedField.validation.minLength"
type="number"
min="0"
class="w-full px-3 py-2 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
>
</div>
<div>
<label class="block text-xs font-medium mb-2" style="color: var(--fg-muted);">Max Length</label>
<input
v-model.number="selectedField.validation.maxLength"
type="number"
min="1"
class="w-full px-3 py-2 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
>
</div>
</div>
<!-- Min/Max for number -->
<div v-if="selectedField.type === 'number'" class="grid grid-cols-2 gap-3">
<div>
<label class="block text-xs font-medium mb-2" style="color: var(--fg-muted);">Min Value</label>
<input
v-model.number="selectedField.validation.min"
type="number"
class="w-full px-3 py-2 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
>
</div>
<div>
<label class="block text-xs font-medium mb-2" style="color: var(--fg-muted);">Max Value</label>
<input
v-model.number="selectedField.validation.max"
type="number"
class="w-full px-3 py-2 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
>
</div>
</div>
<!-- Pattern -->
<div v-if="['text', 'tel', 'url'].includes(selectedField.type)">
<label class="block text-xs font-medium mb-2" style="color: var(--fg-muted);">Regex Pattern</label>
<input
v-model="selectedField.validation.pattern"
type="text"
class="w-full px-3 py-2 rounded-lg border text-sm font-mono"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
placeholder="e.g. ^[A-Za-z]+$"
>
</div>
<!-- Custom error message -->
<div>
<label class="block text-xs font-medium mb-2" style="color: var(--fg-muted);">Custom Error Message</label>
<input
v-model="selectedField.validation.errorMessage"
type="text"
class="w-full px-3 py-2 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
placeholder="Override default validation message"
>
</div>
</div>
</div>
</div>
</div>
<!-- Empty State -->
<div v-else class="rounded-xl border p-8 text-center sticky top-24" style="background: var(--bg-card); border-color: var(--border);">
<div class="w-12 h-12 rounded-xl flex items-center justify-center mx-auto mb-4" style="background: var(--bg-elevated);">
<svg class="w-6 h-6" style="color: var(--fg-muted);" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
</svg>
</div>
<p class="text-sm font-medium mb-1" style="color: var(--fg-muted);">No field selected</p>
<p class="text-xs" style="color: var(--fg-muted);">Click a field to configure its settings</p>
</div>
</aside>
</div>
<!-- Preview Mode -->
<div v-else class="max-w-2xl mx-auto">
<div class="rounded-xl border p-8" style="background: var(--bg-card); border-color: var(--border);">
<h2 class="text-2xl font-bold mb-2">{{ formName || 'Untitled Form' }}</h2>
<p class="text-sm mb-8" style="color: var(--fg-muted);">Please fill out all required fields marked with *</p>
<form @submit.prevent="submitForm" class="space-y-6">
<div v-for="field in fields" :key="field.id" class="animate-slide-up">
<label class="block text-sm font-medium mb-2">
{{ field.label || 'Untitled Field' }}
<span v-if="field.required" style="color: var(--error);">*</span>
</label>
<!-- Text/Email/Tel/URL Input -->
<input
v-if="['text', 'email', 'tel', 'url'].includes(field.type)"
:type="field.type"
v-model="formData[field.id]"
:placeholder="field.placeholder"
:required="field.required"
class="w-full px-4 py-3 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
:class="errors[field.id] ? 'border-red-500' : ''"
@blur="validateField(field)"
@input="clearError(field.id)"
>
<!-- Number Input -->
<input
v-else-if="field.type === 'number'"
type="number"
v-model.number="formData[field.id]"
:placeholder="field.placeholder"
:required="field.required"
:min="field.validation.min"
:max="field.validation.max"
class="w-full px-4 py-3 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
:class="errors[field.id] ? 'border-red-500' : ''"
@blur="validateField(field)"
@input="clearError(field.id)"
>
<!-- Textarea -->
<textarea
v-else-if="field.type === 'textarea'"
v-model="formData[field.id]"
:placeholder="field.placeholder"
:required="field.required"
rows="4"
class="w-full px-4 py-3 rounded-lg border text-sm resize-none"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
:class="errors[field.id] ? 'border-red-500' : ''"
@blur="validateField(field)"
@input="clearError(field.id)"
></textarea>
<!-- Select -->
<select
v-else-if="field.type === 'select'"
v-model="formData[field.id]"
:required="field.required"
class="w-full px-4 py-3 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
:class="errors[field.id] ? 'border-red-500' : ''"
@blur="validateField(field)"
@change="clearError(field.id)"
>
<option value="">Select an option</option>
<option v-for="opt in field.options" :key="opt.id" :value="opt.value">{{ opt.value }}</option>
</select>
<!-- Radio -->
<div v-else-if="field.type === 'radio'" class="space-y-2">
<label v-for="opt in field.options" :key="opt.id" class="flex items-center gap-3 cursor-pointer group">
<div class="relative">
<input
type="radio"
:name="field.id"
:value="opt.value"
v-model="formData[field.id]"
:required="field.required"
class="sr-only peer"
@change="clearError(field.id)"
>
<div class="w-5 h-5 rounded-full border-2 transition-all peer-checked:border-[var(--accent)]" style="border-color: var(--border);"></div>
<div class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-2.5 h-2.5 rounded-full opacity-0 peer-checked:opacity-100 transition-opacity" style="background: var(--accent);"></div>
</div>
<span class="text-sm">{{ opt.value }}</span>
</label>
</div>
<!-- Checkbox Group -->
<div v-else-if="field.type === 'checkbox'" class="space-y-2">
<label v-for="opt in field.options" :key="opt.id" class="flex items-center gap-3 cursor-pointer group">
<div class="relative">
<input
type="checkbox"
:value="opt.value"
v-model="formData[field.id]"
class="sr-only peer"
@change="clearError(field.id)"
>
<div class="w-5 h-5 rounded border-2 transition-all peer-checked:border-[var(--accent)] peer-checked:bg-[var(--accent)]" style="border-color: var(--border);"></div>
<svg class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-3 h-3 opacity-0 peer-checked:opacity-100 transition-opacity" style="color: var(--bg);" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"/>
</svg>
</div>
<span class="text-sm">{{ opt.value }}</span>
</label>
</div>
<!-- Date -->
<input
v-else-if="field.type === 'date'"
type="date"
v-model="formData[field.id]"
:required="field.required"
class="w-full px-4 py-3 rounded-lg border text-sm"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
:class="errors[field.id] ? 'border-red-500' : ''"
@blur="validateField(field)"
@input="clearError(field.id)"
>
<!-- Help Text -->
<p v-if="field.helpText" class="text-xs mt-2" style="color: var(--fg-muted);">{{ field.helpText }}</p>
<!-- Error Message -->
<p v-if="errors[field.id]" class="text-xs mt-2 flex items-center gap-1" style="color: var(--error);">
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
{{ errors[field.id] }}
</p>
</div>
<!-- Submit Button -->
<div class="pt-4">
<button
type="submit"
class="w-full py-3 px-6 rounded-lg font-medium text-sm transition-all hover:opacity-90"
style="background: var(--accent); color: var(--bg);"
>
Submit Form
</button>
</div>
</form>
</div>
</div>
</main>
<!-- Export Modal -->
<div v-if="showExportModal" class="fixed inset-0 z-50 flex items-center justify-center p-4 animate-fade-in" style="background: rgba(0,0,0,0.8);">
<div class="w-full max-w-2xl rounded-xl border p-6" style="background: var(--bg-card); border-color: var(--border);">
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-semibold">Export Form Schema</h3>
<button @click="showExportModal = false" class="p-2 rounded-lg hover:bg-white/5">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
</svg>
</button>
</div>
<pre class="p-4 rounded-lg text-xs font-mono overflow-auto max-h-96" style="background: var(--bg-elevated); color: var(--accent);">{{ exportedSchema }}</pre>
<div class="flex justify-end gap-3 mt-4">
<button
@click="copyToClipboard"
class="px-4 py-2 rounded-lg border text-sm font-medium transition-all hover:bg-white/5"
style="border-color: var(--border);"
>
{{ copied ? 'Copied!' : 'Copy to Clipboard' }}
</button>
</div>
</div>
</div>
<!-- Success Toast -->
<Transition name="list">
<div v-if="showSuccessToast" class="fixed bottom-6 right-6 px-5 py-3 rounded-lg flex items-center gap-3 shadow-lg" style="background: var(--accent); color: var(--bg);">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
</svg>
<span class="text-sm font-medium">Form submitted successfully!</span>
</div>
</Transition>
</div>
<script>
const { createApp, ref, reactive, computed, watch } = Vue;
createApp({
setup() {
// State
const mode = ref('build');
const formName = ref('Contact Form');
const fields = ref([]);
const selectedField = ref(null);
const isDragOver = ref(false);
const draggedFieldType = ref(null);
const draggedFieldIndex = ref(null);
const showExportModal = ref(false);
const exportedSchema = ref('');
const copied = ref(false);
const showSuccessToast = ref(false);
const formData = reactive({});
const errors = reactive({});
// Field Types
const fieldTypes = ref([
{
type: 'text',
label: 'Text Input',
description: 'Single line text field',
color: '#00d4aa',
icon: '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h7"/></svg>'
},
{
type: 'email',
label: 'Email',
description: 'Email address field',
color: '#3b82f6',
icon: '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>'
},
{
type: 'number',
label: 'Number',
description: 'Numeric input field',
color: '#8b5cf6',
icon: '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 20l4-16m2 16l4-16M6 9h14M4 15h14"/></svg>'
},
{
type: 'textarea',
label: 'Text Area',
description: 'Multi-line text field',
color: '#f59e0b',
icon: '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h16M4 18h10"/></svg>'
},
{
type: 'select',
label: 'Dropdown',
description: 'Select from options',
color: '#ec4899',
icon: '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/></svg>'
},
{
type: 'radio',
label: 'Radio Buttons',
description: 'Single choice selection',
color: '#10b981',
icon: '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>'
},
{
type: 'checkbox',
label: 'Checkboxes',
description: 'Multiple choice selection',
color: '#06b6d4',
icon: '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"/></svg>'
},
{
type: 'date',
label: 'Date Picker',
description: 'Date selection field',
color: '#f97316',
icon: '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>'
},
{
type: 'tel',
label: 'Phone',
description: 'Phone number field',
color: '#84cc16',
icon: '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"/></svg>'
},
{
type: 'url',
label: 'URL',
description: 'Website URL field',
color: '#a855f7',
icon: '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"/></svg>'
}
]);
// Generate unique ID
const generateId = () => `field_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
// Create new field
const createField = (type) => {
const baseField = {
id: generateId(),
type,
label: '',
placeholder: '',
helpText: '',
required: false,
validation: {
minLength: null,
maxLength: null,
min: null,
max: null,
pattern: '',
errorMessage: ''
}
};
if (['select', 'radio', 'checkbox'].includes(type)) {
baseField.options = [
{ id: generateId(), value: 'Option 1' },
{ id: generateId(), value: 'Option 2' }
];
}
return baseField;
};
// Add field
const addField = (type) => {
const field = createField(type);
fields.value.push(field);
selectedField.value = field;
initializeFormData(field);
};
// Initialize form data for field
const initializeFormData = (field) => {
if (field.type === 'checkbox') {
formData[field.id] = [];
} else {
formData[field.id] = '';
}
};
// Select field
const selectField = (field) => {
selectedField.value = field;
};
// Remove field
const removeField = (index) => {
const fieldId = fields.value[index].id;
delete formData[fieldId];
delete errors[fieldId];
fields.value.splice(index, 1);
if (selectedField.value?.id === fieldId) {
selectedField.value = null;
}
};
// Duplicate field
const duplicateField = (index) => {
const original = fields.value[index];
const duplicate = JSON.parse(JSON.stringify(original));
duplicate.id = generateId();
if (duplicate.options) {
duplicate.options = duplicate.options.map(opt => ({ ...opt, id: generateId() }));
}
fields.value.splice(index + 1, 0, duplicate);
initializeFormData(duplicate);
};
// Add option
const addOption = () => {
if (selectedField.value && selectedField.value.options) {
selectedField.value.options.push({ id: generateId(), value: `Option ${selectedField.value.options.length + 1}` });
}
};
// Remove option
const removeOption = (index) => {
if (selectedField.value && selectedField.value.options) {
selectedField.value.options.splice(index, 1);
}
};
// Drag and Drop
const onDragStart = (e, type) => {
draggedFieldType.value = type;
e.dataTransfer.effectAllowed = 'copy';
};
const onDrop = (e) => {
isDragOver.value = false;
if (draggedFieldType.value) {
addField(draggedFieldType.value);
draggedFieldType.value = null;
}
};
const onFieldDragStart = (e, index) => {
draggedFieldIndex.value = index;
e.dataTransfer.effectAllowed = 'move';
};
const onFieldDragOver = (e, index) => {
e.dataTransfer.dropEffect = 'move';
};
const onFieldDrop = (e, targetIndex) => {
if (draggedFieldIndex.value !== null && draggedFieldIndex.value !== targetIndex) {
const field = fields.value.splice(draggedFieldIndex.value, 1)[0];
fields.value.splice(targetIndex, 0, field);
}
};
const onFieldDragEnd = () => {
draggedFieldIndex.value = null;
};
// Validation
const validateField = (field) => {
const value = formData[field.id];
let error = '';
if (field.required) {
if (field.type === 'checkbox') {
if (!value || value.length === 0) {
error = field.validation.errorMessage || 'At least one option is required';
}
} else if (!value && value !== 0) {
error = field.validation.errorMessage || 'This field is required';
}
}
if (!error && value) {
if (field.type === 'email' && value) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(value)) {
error = field.validation.errorMessage || 'Please enter a valid email address';
}
}
if (field.validation.minLength && value.length < field.validation.minLength) {
error = field.validation.errorMessage || `Minimum ${field.validation.minLength} characters required`;
}
if (field.validation.maxLength && value.length > field.validation.maxLength) {
error = field.validation.errorMessage || `Maximum ${field.validation.maxLength} characters allowed`;
}
if (field.type === 'number') {
if (field.validation.min !== null && value < field.validation.min) {
error = field.validation.errorMessage || `Minimum value is ${field.validation.min}`;
}
if (field.validation.max !== null && value > field.validation.max) {
error = field.validation.errorMessage || `Maximum value is ${field.validation.max}`;
}
}
if (field.validation.pattern && value) {
try {
const regex = new RegExp(field.validation.pattern);
if (!regex.test(value)) {
error = field.validation.errorMessage || 'Please match the requested format';
}
} catch (e) {
console.error('Invalid regex pattern');
}
}
}
if (error) {
errors[field.id] = error;
}
};
const clearError = (fieldId) => {
delete errors[fieldId];
};
// Form submission
const submitForm = () => {
// Validate all fields
fields.value.forEach(field => {
validateField(field);
});
// Check for errors
const hasErrors = Object.keys(errors).length > 0;
if (!hasErrors) {
console.log('Form submitted:', formData);
showSuccessToast.value = true;
setTimeout(() => {
showSuccessToast.value = false;
}, 3000);
}
};
// Export
const exportSchema = () => {
const schema = {
name: formName.value,
createdAt: new Date().toISOString(),
fields: fields.value.map(f => ({
type: f.type,
label: f.label,
placeholder: f.placeholder,
helpText: f.helpText,
required: f.required,
validation: f.validation,
...(f.options && { options: f.options.map(o => o.value) })
}))
};
exportedSchema.value = JSON.stringify(schema, null, 2);
showExportModal.value = true;
copied.value = false;
};
const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(exportedSchema.value);
copied.value = true;
setTimeout(() => {
copied.value = false;
}, 2000);
} catch (err) {
console.error('Failed to copy:', err);
}
};
// Initialize with sample fields
const initSampleForm = () => {
const nameField = createField('text');
nameField.label = 'Full Name';
nameField.placeholder = 'Enter your full name';
nameField.required = true;
nameField.validation.minLength = 2;
const emailField = createField('email');
emailField.label = 'Email Address';
emailField.placeholder = 'you@example.com';
emailField.required = true;
const messageField = createField('textarea');
messageField.label = 'Message';
messageField.placeholder = 'Type your message here...';
messageField.required = true;
messageField.validation.minLength = 10;
fields.value = [nameField, emailField, messageField];
fields.value.forEach(f => initializeFormData(f));
};
initSampleForm();
return {
mode,
formName,
fields,
selectedField,
fieldTypes,
isDragOver,
showExportModal,
exportedSchema,
copied,
showSuccessToast,
formData,
errors,
addField,
selectField,
removeField,
duplicateField,
addOption,
removeOption,
onDragStart,
onDrop,
onFieldDragStart,
onFieldDragOver,
onFieldDrop,
onFieldDragEnd,
validateField,
clearError,
submitForm,
exportSchema,
copyToClipboard
};
}
}).component('FieldPreview', {
props: ['field'],
template: `
<div>
<input
v-if="['text', 'email', 'number', 'tel', 'url', 'date'].includes(field.type)"
:type="field.type"
:placeholder="field.placeholder || 'Enter text...'"
class="w-full px-3 py-2 rounded-lg border text-sm opacity-60"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
disabled
>
<textarea
v-else-if="field.type === 'textarea'"
:placeholder="field.placeholder || 'Enter text...'"
rows="3"
class="w-full px-3 py-2 rounded-lg border text-sm opacity-60 resize-none"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
disabled
></textarea>
<select
v-else-if="field.type === 'select'"
class="w-full px-3 py-2 rounded-lg border text-sm opacity-60"
style="background: var(--bg-elevated); border-color: var(--border); color: var(--fg);"
disabled
>
<option v-for="opt in field.options" :key="opt.id">{{ opt.value }}</option>
</select>
<div v-else-if="field.type === 'radio'" class="flex flex-wrap gap-4">
<label v-for="opt in field.options" :key="opt.id" class="flex items-center gap-2 opacity-60">
<div class="w-4 h-4 rounded-full border-2" style="border-color: var(--border);"></div>
<span class="text-sm">{{ opt.value }}</span>
</label>
</div>
<div v-else-if="field.type === 'checkbox'" class="flex flex-wrap gap-4">
<label v-for="opt in field.options" :key="opt.id" class="flex items-center gap-2 opacity-60">
<div class="w-4 h-4 rounded border-2" style="border-color: var(--border);"></div>
<span class="text-sm">{{ opt.value }}</span>
</label>
</div>
</div>
`
}).mount('#app');
</script>
</body>
</html>
Key Features
Dynamic Field Generation
- 10 field types: Text, Email, Number, Textarea, Select, Radio, Checkboxes, Date, Phone, URL
- Click or drag fields from the left panel to add them to your form
- Drag to reorder fields within the form canvas
- Duplicate/Delete fields with hover actions
Validation System
- Required field validation
- Min/Max length for text fields
- Min/Max value for number fields
- Regex pattern support for custom validation
- Custom error messages for each field
- Real-time validation on blur with visual feedback
Configuration Options
- Field labels and placeholders
- Help text for user guidance
- Dynamic option management for select/radio/checkbox
- Toggle switches for boolean settings
Interactions
- Staggered entrance animations for fields
- Smooth transitions when reordering/deleting
- Drag-over visual feedback on drop zones
- Hover states reveal action buttons
- Toggle switches with smooth state transitions
- Toast notifications on form submission
Design
- Dark technical theme with cyan accent
- Grid background pattern for depth
- Consistent spacing and typography scale
- Space Grotesk display font + JetBrains Mono for code
- Accessible focus states and reduced motion support