Vueform Documentation

repository·main·Indexed 23 days ago

https://github.com/vueform/vueform

An open-source form framework for Vue.js (version 1.13.13) that standardizes form building, rendering, validation, and processing. It features a rich library of 25+ elements, a Drag and Drop Builder, Tailwind CSS theming, 50+ validators, conditional logic, multi-step form support, and global i18n support. Includes an official module for Nuxt (@vueform/nuxt).

Tokens
39.8K
Snippets
41
Records
135
Agent score
80%

What's inside Vueform

  1. Overview of Vueform features

    main

    Vueform is an open-source form framework for Vue.js designed to standardize the form building process. Key features include:

    • Rich Element Library: 25+ form elements including multi-file uploads, date pickers, and rich text editors.
    • Advanced Layout: Support for element nesting and repeating elements.
    • Theming: A complete theming and templating system with Tailwind CSS support.
    • Robust Validation: 50+ validators including async, dependent, and custom rules.
    • Logic & Flow: Conditional logic (with/and/or groups) and built-in support for multi-step forms.
    • Accessibility & i18n: Fully accessible components with global i18n support for translating form contents.
  2. Create a new Vueform project

    main

    You can quickly scaffold a new Vueform project using any of the following package manager commands. This is the recommended way to get started with a pre-configured environment.

    npm create vueform@latest
    
    yarn create vueform
    
    pnpm create vueform
    
    bun create vueform
  3. Use the Vueform Drag and Drop Builder

    main

    For rapid form development, you can use the Vueform Drag and Drop Builder. This tool allows you to visually construct forms and then export the resulting configuration as a native Vue component for use in your application.

    https://builder.vueform.com/demo
  4. Understand the FormElements template structure in the Vueform theme

    main

    The FormElements component in the Vueform theme acts as a container for form elements. It extends the base FormElements template from the blank theme and introduces a defaultClasses configuration object. This object defines how container classes are applied based on the current responsive size.

    Key properties in the defaultClasses object:

    • container: The base class for the container (vf-row).
    • container_sm, container_md, container_lg: Responsive classes applied based on the breakpoint.
    • $container: A functional resolver that takes current classes and the component's Size to return an array of active classes.
    • merge: A boolean flag (defaults to true) indicating if classes should be merged.
    // Conceptual representation of the defaultClasses structure
    data() {
      return {
        merge: true,
        defaultClasses: {
          container: 'vf-row',
          container_sm: 'vf-row-sm',
          container_md: '',
          container_lg: 'vf-row-lg',
          $container: (classes, { Size }) => ([
            classes.container,
            classes[`container_${Size}`]
          ]),
        }
      }
    }
  5. Define column size formats

    main

    The Columns service accepts several formats for defining column sizes. These are automatically serialized into a breakpoint-based structure.

    1. Simple Number/String

    Provides a single size for the container at the default breakpoint.

    columns: 8
    // Serializes to: { default: { container: 8 } }

    2. Object by Type

    Define sizes for specific parts (container, label, wrapper).

    // Single size for all types at default breakpoint
    columns: { container: 8 }
    
    // Specific sizes for types with breakpoint overrides
    columns: { 
      container: 8, 
      wrapper: { default: 8, lg: 12 } 
    }

    3. Object by Breakpoint

    Define sizes for the container across different breakpoints.

    // Container size varies by breakpoint
    columns: { lg: 8, md: { container: 6 } }
  6. How to use expressions in Vueform

    main

    Expressions in Vueform are strings that contain placeholders wrapped in curly braces {}. The expression engine parses these placeholders, evaluates them against the current form data, and replaces them with the resulting values.

    Syntax Rules

    • Wrapping: Expressions must be wrapped in curly braces, e.g., {SUM(field1, field2)}. If you provide a raw expression without braces, the service will automatically wrap it.
    • Wildcards: The engine supports wildcard replacement to resolve paths relative to the current data context.
    • Escaping: To use literal curly braces in a string, escape them using \{ and \}.

    Example Usage

    If you have a field that needs to display a sum of other fields:

    {SUM(price, tax)}

    If you need to check if a field is empty:

    {NOT_EMPTY(username)}
  7. How ElementAddon handles different addon types

    main

    The ElementAddon component is a template used to render addons for Vueform elements. It supports three distinct types of addons:

    1. Component: If the addon is a Vue component, it is rendered using the <component :is="addon"/> pattern.
    2. HTML: If the addon is a string, it is rendered as raw HTML using the v-html directive.
    3. Slot: If the addon is defined as a slot (isSlot), the component renders the content provided to the slot.

    All addon types are wrapped in a container and a wrapper div, which use classes defined in the classes object (e.g., classes.container and classes.wrapper).

    <!-- If addon is a component -->
    <div v-if="addon && isAddonComponent" :class="classes.container">
      <div :class="classes.wrapper">
        <component :is="addon"/>
      </div>
    </div
    
    <!-- If addon is HTML -->
    <div v-else-if="addon" :class="classes.container">
      <div :class="classes.wrapper" v-html="addon"></div
    </div
    
    <!-- If addon is a slot -->
    <div v-else-if="isSlot" :class="classes.container">
      <div :class="classes.wrapper"><slot/></div
    </div
  8. Configure column layouts in Vueform

    main

    Vueform uses a Columns service to manage grid-based layouts. You can define column sizes for different parts of an element (like container, label, or wrapper) across various breakpoints.

    Column configurations can be provided at multiple levels of specificity, which are merged in the following order (later definitions override earlier ones):

    1. configPresetColumns: Global configuration presets.
    2. configColumns: Global configuration.
    3. formPresetColumns: Presets applied to a specific form.
    4. formColumns: Configuration for a specific form.
    5. elementPresetColumns: Presets applied to a specific element.
    6. elementColumns: Configuration for a specific element.

    Supported Column Types

    • container: The main container of the element.
    • label: The size allocated to the element's label.
    • wrapper: The size allocated to the element's wrapper.
    • innerContainer: A calculated type used for internal layout logic (typically 12 - label_size).
  9. Initialize Vueform

    main

    To use Vueform, you call the default export function (the installer). This function returns a Vueform instance which you then use to install the library into your Vue application. You can pass an initial configuration object, custom components, validation rules, and custom services during initialization.

    Arguments:

    • config (Object): The base configuration for Vueform.
    • components (Object): A map of custom components to register.
    • rules (Object): Custom validation rules.
    • services (Object): Custom service overrides (e.g., axios, validation).
  10. Use the Tailwind theme in Vueform

    main
    The Tailwind theme provides a complete set of templates, classes, columns, and presets designed for Tailwind CSS. You can import the default theme object or use the prefix function to add a custom prefix to all Tailwind classes (e.g., to avoid conflicts with other Tailwind configurations).