# SonicJS Forms - Interactive Examples **Live, interactive examples showcasing all features of the SonicJS Forms system.** --- ## ๐ฏ Navigation - [Basic Form Examples](#-basic-form-examples) - [Multi-Page Wizards](#-multi-page-wizards) - [Advanced Components](#-advanced-components) - [Validation & Conditional Logic](#-validation--conditional-logic) - [Headless Integration](#-headless-integration) - [Custom Styling](#-custom-styling) - [File Uploads](#-file-uploads) - [Embedding Examples](#-embedding-examples) --- ## ๐ Basic Form Examples ### Example 1: Simple Contact Form **What it demonstrates:** Basic text fields, email validation, text area, and submit button. #### Live Preview ``` http://localhost:8787/forms/simple_contact ``` #### Schema (JSON) ```json { "display": "form", "components": [ { "type": "textfield", "key": "name", "label": "Full Name", "placeholder": "Enter your name", "validate": { "required": true, "minLength": 2, "maxLength": 100 } }, { "type": "email", "key": "email", "label": "Email Address", "placeholder": "you@example.com", "validate": { "required": true } }, { "type": "textarea", "key": "message", "label": "Message", "placeholder": "How can we help you?", "rows": 5, "validate": { "required": true, "minLength": 10 } }, { "type": "button", "action": "submit", "label": "Send Message", "theme": "primary" } ] } ``` #### How to Create ```typescript // Via API await fetch('/admin/forms', { method: 'POST', body: new URLSearchParams({ name: 'simple_contact', displayName: 'Simple Contact Form', category: 'contact' }) }); // Then use builder to add components ``` --- ### Example 2: Newsletter Signup **What it demonstrates:** Minimal form with checkbox for consent. #### Live Preview ``` http://localhost:8787/forms/newsletter_signup ``` #### Schema ```json { "display": "form", "components": [ { "type": "email", "key": "email", "label": "Email Address", "validate": { "required": true } }, { "type": "checkbox", "key": "consent", "label": "I agree to receive marketing emails", "validate": { "required": true } }, { "type": "button", "action": "submit", "label": "Subscribe" } ] } ``` --- ### Example 3: Feedback Survey **What it demonstrates:** Radio buttons, select dropdowns, ratings. #### Schema ```json { "display": "form", "components": [ { "type": "radio", "key": "satisfaction", "label": "How satisfied are you with our service?", "values": [ { "label": "Very Satisfied", "value": "very_satisfied" }, { "label": "Satisfied", "value": "satisfied" }, { "label": "Neutral", "value": "neutral" }, { "label": "Dissatisfied", "value": "dissatisfied" }, { "label": "Very Dissatisfied", "value": "very_dissatisfied" } ], "validate": { "required": true } }, { "type": "select", "key": "category", "label": "What category best describes your feedback?", "data": { "values": [ { "label": "Product Quality", "value": "quality" }, { "label": "Customer Service", "value": "service" }, { "label": "Pricing", "value": "pricing" }, { "label": "Delivery", "value": "delivery" }, { "label": "Other", "value": "other" } ] } }, { "type": "textarea", "key": "comments", "label": "Additional Comments", "rows": 4 } ] } ``` --- ## ๐ง Multi-Page Wizards ### Example 4: Job Application Wizard **What it demonstrates:** Multi-step form with personal info โ experience โ upload resume. #### Live Preview ``` http://localhost:8787/forms/job_application ``` #### Schema Structure ```json { "display": "wizard", "components": [ { "type": "panel", "key": "personalInfo", "title": "Personal Information", "components": [ { "type": "textfield", "key": "firstName", "label": "First Name", "validate": { "required": true } }, { "type": "textfield", "key": "lastName", "label": "Last Name", "validate": { "required": true } }, { "type": "email", "key": "email", "label": "Email", "validate": { "required": true } }, { "type": "phoneNumber", "key": "phone", "label": "Phone Number" } ] }, { "type": "panel", "key": "experience", "title": "Work Experience", "components": [ { "type": "textfield", "key": "currentPosition", "label": "Current Position" }, { "type": "textfield", "key": "currentCompany", "label": "Current Company" }, { "type": "number", "key": "yearsExperience", "label": "Years of Experience", "validate": { "min": 0, "max": 50 } } ] }, { "type": "panel", "key": "documents", "title": "Documents", "components": [ { "type": "file", "key": "resume", "label": "Upload Resume", "storage": "r2", "fileTypes": [ { "label": "PDF", "value": "application/pdf" }, { "label": "Word", "value": "application/vnd.openxmlformats-officedocument.wordprocessingml.document" } ], "validate": { "required": true } }, { "type": "textarea", "key": "coverLetter", "label": "Cover Letter", "rows": 8 } ] } ] } ``` #### Navigation Features - โ Previous/Next buttons auto-generated - โ Progress indicator shows current step - โ Per-page validation (can't proceed with errors) - โ Data persists when going back/forward --- ### Example 5: Product Registration Wizard **What it demonstrates:** Conditional pages based on previous answers. #### Conditional Logic ```json { "display": "wizard", "components": [ { "type": "panel", "key": "productType", "title": "Product Type", "components": [ { "type": "select", "key": "type", "label": "What product did you purchase?", "data": { "values": [ { "label": "Software", "value": "software" }, { "label": "Hardware", "value": "hardware" } ] } } ] }, { "type": "panel", "key": "softwareDetails", "title": "Software Details", "conditional": { "show": true, "when": "type", "eq": "software" }, "components": [ { "type": "textfield", "key": "licenseKey", "label": "License Key" } ] }, { "type": "panel", "key": "hardwareDetails", "title": "Hardware Details", "conditional": { "show": true, "when": "type", "eq": "hardware" }, "components": [ { "type": "textfield", "key": "serialNumber", "label": "Serial Number" } ] } ] } ``` --- ## ๐จ Advanced Components ### Example 6: Address with Google Maps **What it demonstrates:** Google Maps autocomplete for addresses. #### Configuration ```json { "type": "address", "key": "address", "label": "Delivery Address", "map": { "key": "YOUR_GOOGLE_MAPS_API_KEY", "region": "US" }, "provider": "google", "validate": { "required": true } } ``` #### Setup Required 1. Get Google Maps API key 2. Enable Places API and Maps JavaScript API 3. Add key to component's `map.key` field in builder **See:** [Google Maps Setup Guide](./GOOGLE_MAPS_SETUP.md) --- ### Example 7: Signature Component **What it demonstrates:** Digital signature capture. ```json { "type": "signature", "key": "signature", "label": "Sign Here", "width": "100%", "height": "150px", "penColor": "black", "backgroundColor": "rgb(245,245,245)", "validate": { "required": true } } ``` --- ### Example 8: Date & Time Picker **What it demonstrates:** Date selection with validation. ```json { "type": "datetime", "key": "appointmentDate", "label": "Preferred Appointment Date", "format": "yyyy-MM-dd", "enableDate": true, "enableTime": false, "validate": { "required": true }, "datePicker": { "minDate": "2026-01-01", "maxDate": "2026-12-31", "disable": ["2026-12-25", "2026-01-01"] } } ``` --- ## โ Validation & Conditional Logic ### Example 9: Dynamic Field Visibility **What it demonstrates:** Show/hide fields based on user input. ```json { "components": [ { "type": "checkbox", "key": "hasCompany", "label": "I'm registering on behalf of a company" }, { "type": "textfield", "key": "companyName", "label": "Company Name", "conditional": { "show": true, "when": "hasCompany", "eq": true }, "validate": { "required": true } }, { "type": "textfield", "key": "taxId", "label": "Tax ID", "conditional": { "show": true, "when": "hasCompany", "eq": true } } ] } ``` --- ### Example 10: Complex Validation Rules **What it demonstrates:** Custom validation patterns. ```json { "components": [ { "type": "textfield", "key": "username", "label": "Username", "validate": { "required": true, "minLength": 3, "maxLength": 20, "pattern": "^[a-zA-Z0-9_]+$", "customMessage": "Username must be 3-20 characters and contain only letters, numbers, and underscores" } }, { "type": "password", "key": "password", "label": "Password", "validate": { "required": true, "minLength": 8, "pattern": "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]", "customMessage": "Password must contain uppercase, lowercase, number, and special character" } }, { "type": "password", "key": "confirmPassword", "label": "Confirm Password", "validate": { "required": true, "custom": "valid = (input === data.password) ? true : 'Passwords must match';" } } ] } ``` --- ## ๐ Headless Integration ### Example 11: React Integration **Live Demo:** See full code in [FORMS_HEADLESS_FRONTEND.md](./FORMS_HEADLESS_FRONTEND.md) ```tsx import { Form } from '@formio/react'; function ContactForm() { const [schema, setSchema] = useState(null); useEffect(() => { fetch('https://your-api.com/forms/contact/schema') .then(r => r.json()) .then(data => setSchema(data.schema)); }, []); const handleSubmit = async (submission) => { await fetch('https://your-api.com/api/forms/contact/submit', { method: 'POST', body: JSON.stringify({ data: submission.data }) }); }; return schema ?
:Total: $0
" } ] } ] } ``` --- ## ๐ฏ Best Practices Demonstrated ### โ Form Design - Keep forms under 10 fields when possible - Use wizards for forms >6 fields - Group related fields in panels - Use clear, actionable button text - Provide helpful placeholder text ### โ Validation - Mark required fields clearly - Provide instant feedback on errors - Use appropriate input types (email, tel, number) - Add custom validation messages - Validate before allowing progression ### โ User Experience - Show progress in wizards - Allow users to go back and edit - Persist data between pages - Show clear success messages - Handle errors gracefully ### โ Performance - Lazy load forms with scripts - Use CDN for Form.io library - Minimize custom CSS - Cache form schemas - Optimize file upload sizes --- ## ๐ Related Documentation - **[Quick Reference](./FORMS_QUICK_REFERENCE.md)** - One-page cheat sheet - **[Embedding Guide](./FORMS_EMBEDDING_GUIDE.md)** - How to embed forms with custom styling - **[Headless Frontend](./FORMS_HEADLESS_FRONTEND.md)** - React, Astro, Angular, Vue examples - **[API Reference](./FORMS_API.md)** - Programmatic form creation - **[Wizard Forms](./FORMIO_WIZARD_FORMS.md)** - Multi-page forms guide - **[Testing Guide](./FORMS_TESTING_SUITE.md)** - E2E, unit, and manual tests --- ## ๐ Need More Examples? **Can't find what you're looking for?** - ๐ Check [Form.io Examples](https://formio.github.io/formio.js/app/examples/) for more Form.io features - ๐ฌ Join our Discord for help - ๐ Open a GitHub issue for documentation requests - ๐ง Contact support@sonicjs.com --- **Last Updated:** January 2026 **Version:** 1.0.0