Form Editor

Build forms visually with drag-and-drop designer

Visual Form Editor

The Vyuh Form Editor is a powerful visual designer that allows you to build complex forms without writing code. Create, edit, and export forms using an intuitive drag-and-drop interface.

Overview

The Form Editor provides:

  • Drag-and-Drop Builder: Build forms by dragging fields from a palette
  • Live Preview: See your form as you build it
  • Property Editor: Configure field properties visually
  • Field Palette: Searchable catalog of all field types
  • JSON Export: Export forms as JSON configuration
  • Import/Export: Save and load form designs
  • Template Library: Save reusable form templates

Getting Started

Installation

Add vyuh_form_editor to your pubspec.yaml:

dependencies:
  vyuh_form_editor: ^latest_version

Basic Usage

import 'package:flutter/material.dart';
import 'package:vyuh_form_editor/vyuh_form_editor.dart';

class FormEditorScreen extends StatefulWidget {
  @override
  State<FormEditorScreen> createState() => _FormEditorScreenState();
}

class _FormEditorScreenState extends State<FormEditorScreen> {
  late final FormEditorController controller;

  @override
  void initState() {
    super.initState();
    controller = FormEditorController();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Form Editor'),
        actions: [
          IconButton(
            icon: Icon(Icons.save),
            onPressed: _saveForm,
          ),
          IconButton(
            icon: Icon(Icons.preview),
            onPressed: _previewForm,
          ),
        ],
      ),
      body: FormEditor(
        controller: controller,
        onFormChanged: (form) {
          print('Form updated: ${form.title}');
        },
      ),
    );
  }

  void _saveForm() {
    final formJson = controller.exportToJson();
    // Save to database or file
    print('Form JSON: $formJson');
  }

  void _previewForm() {
    final form = controller.buildForm();
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (_) => FormPreviewScreen(form: form),
      ),
    );
  }
}

User Interface

The Form Editor consists of four main panels:

1. Field Palette (Left)

Browse and search all available field types:

  • Text Fields: TextField, PasswordField, TextArea
  • Numbers: NumberField, SliderField
  • Dates: DateField, TimeField, DateTimeField
  • Selection: SelectField, RadioField, CheckboxField
  • Files: FileField, ImageField
  • Advanced: FormulaField, SignatureField, RatingField

Drag fields from the palette onto the canvas to add them to your form.

2. Form Canvas (Center)

The main area where you build your form:

  • Drag fields from the palette
  • Reorder fields by dragging
  • Click to select and edit fields
  • Delete fields with the trash icon
  • Group fields into sections

3. Property Editor (Right)

Configure the selected field's properties:

Basic Properties:

  • Name (unique identifier)
  • Label (display text)
  • Placeholder/Hint
  • Description/Help text
  • Initial value

Validation:

  • Required checkbox
  • Built-in validators
  • Custom validation rules
  • Error messages

Appearance:

  • Field width
  • Visibility conditions
  • Custom styling

Behavior:

  • Enable/Disable
  • Read-only
  • Conditional logic

4. Toolbar (Top)

Quick actions:

  • Save form
  • Load form
  • Export JSON
  • Preview
  • Undo/Redo
  • Form settings

Building Forms

Adding Fields

  1. Find the field type in the palette
  2. Drag it onto the canvas
  3. Drop it where you want it
  4. Configure properties in the right panel

Configuring Fields

Click any field to edit its properties:

// Example: Configure an email field
TextField(
  name: 'email',              // Set in Properties
  label: 'Email Address',     // Set in Properties
  hint: 'your@email.com',     // Set in Properties
  validators: [               // Add via Validation panel
    required(),
    email(),
  ],
  validateOnChange: true,     // Set in Behavior panel
)

Field Reordering

Reorder fields by:

  1. Click and hold a field
  2. Drag to new position
  3. Drop to place

Field Groups

Create sections to organize fields:

  1. Add a "Field Group" from the palette
  2. Drag fields into the group
  3. Configure group title and description

Conditional Fields

Show/hide fields based on conditions:

  1. Select a field
  2. Go to Behavior panel
  3. Set visibility condition:
    {{employmentStatus}} == "employed"

Form Properties

Configure global form settings:

General

  • Form Title: Display title
  • Description: Form description
  • Submit Button Text: Custom button label
  • Show Progress: For multi-step forms

Validation

  • Validate on Change: Validate as user types
  • Show Error Summary: Display all errors at top
  • Scroll to Error: Auto-scroll to first error

Submission

  • Success Message: Message after submission
  • Redirect URL: Where to go after submit
  • Reset After Submit: Clear form on success

Multi-Step Forms

Create wizard-style forms:

  1. Click "Add Step" in toolbar
  2. Name the step
  3. Add fields to the step
  4. Configure step validation
  5. Set step visibility conditions
// Multi-step form structure
StepForm(
  steps: [
    FormStep(
      title: 'Personal Info',
      fields: [...],
    ),
    FormStep(
      title: 'Contact Details',
      fields: [...],
    ),
    FormStep(
      title: 'Review',
      fields: [...],
    ),
  ],
)

Advanced Features

Formula Fields

Create calculated fields:

  1. Add FormulaField from palette
  2. Set formula in properties:
    {{quantity}} * {{price}}
  3. Select dependencies
  4. Choose format (currency, percentage, etc.)

Field Dependencies

Make fields dependent on others:

Example: City depends on State

SelectField(
  name: 'state',
  label: 'State',
  options: stateOptions,
),
SelectField(
  name: 'city',
  label: 'City',
  optionsUrl: '/api/cities?state={{state}}',
  dependsOn: ['state'],
)

Custom Validators

Add custom validation rules:

  1. Select field
  2. Go to Validation panel
  3. Click "Add Custom Validator"
  4. Enter validation logic:
    function validate(value) {
      if (value.length < 8) {
        return "Minimum 8 characters";
      }
      return null;
    }

Export & Import

Export to JSON

final formJson = controller.exportToJson();

// Result:
{
  "title": "Contact Form",
  "fields": [
    {
      "type": "text",
      "name": "name",
      "label": "Your Name",
      "validators": [
        {"type": "required"}
      ]
    },
    // ... more fields
  ]
}

Import from JSON

final formJson = await loadFormJson();
controller.importFromJson(formJson);

Save as Template

controller.saveAsTemplate(
  name: 'Contact Form Template',
  category: 'General',
);

Integration with Code

Use editor-generated forms in your app:

// 1. Export JSON from editor
final formJson = controller.exportToJson();

// 2. Save to assets or database
await saveFormDefinition('contact_form', formJson);

// 3. Load and render in app
final formJson = await loadFormDefinition('contact_form');
final form = FormBuilder.fromJson(formJson);

// 4. Display the form
FormRenderer(
  form: form,
  onSubmit: handleSubmit,
)

Best Practices

Naming Conventions

  • Use camelCase for field names: firstName, emailAddress
  • Make names descriptive: employeeEmail not email1
  • Avoid special characters in names

Field Organization

  • Group related fields together
  • Use field groups for sections
  • Order fields logically (name before address, etc.)
  • Place required fields first

Validation

  • Add helpful error messages
  • Validate on change for important fields
  • Use pattern validators for formatted input
  • Provide examples in placeholders

Performance

  • Limit formula field dependencies
  • Avoid deeply nested conditional logic
  • Use field groups to improve rendering
  • Test with large datasets

Keyboard Shortcuts

Speed up form building:

  • Ctrl/Cmd + S: Save form
  • Ctrl/Cmd + Z: Undo
  • Ctrl/Cmd + Y: Redo
  • Delete: Remove selected field
  • Ctrl/Cmd + D: Duplicate field
  • Ctrl/Cmd + P: Preview form
  • Ctrl/Cmd + E: Export JSON

Examples

Contact Form

Build a simple contact form:

  1. Add TextField for name
  2. Add TextField for email with email validator
  3. Add TextField for message (multiline)
  4. Add BooleanField for consent
  5. Configure submit button

Registration Form

Create a multi-step registration:

  1. Step 1: Account Info (username, password)
  2. Step 2: Personal Info (name, birthdate)
  3. Step 3: Contact (email, phone)
  4. Step 4: Review and Submit

Survey Form

Design a survey with various question types:

  1. RadioField for single-choice questions
  2. CheckboxField for multiple-choice
  3. SliderField for rating scales
  4. TextField for open-ended responses

Next Steps

On this page