Skip to content

Form Configuration

Configure UI-related settings for forms and understand each configuration option.

Form Global Configuration

Setting Form Configuration

Set form configuration using one of these methods:

  • Component Mode

Set form configuration in the template:

html
<form-create :option="option"></form-create>
  • Global Method

Create forms and configure them using global methods:

js
window.formCreate.create(rule, option)

Structure

Global configuration supports these options:

  • form: Form overall display rule configuration
  • row: Form component layout configuration
  • submitBtn: Submit button style configuration
  • resetBtn: Reset button style configuration
  • info: Component hint message configuration
  • wrap: Configure FormItem

Configure Form (form)

  • Type: Object

  • Description: Configure form display settings, including label and input alignment.

  • Default Value:

js
  {
    layout: 'vertical',
    labelAlign: 'right',
    labelWidth: '125px'
  }

Configuration Examples

Basic Configuration

js
const option = {
    form: {
        layout: 'vertical',  // Layout mode: 'vertical' | 'horizontal' | 'inline'
        labelAlign: 'right', // Label alignment: 'left' | 'right' | 'top'
        labelWidth: '125px'  // Label width
    }
}

Horizontal Layout

js
const option = {
    form: {
        layout: 'horizontal',  // Horizontal layout
        labelAlign: 'right',
        labelWidth: '125px'
    }
}

Inline Layout

js
const option = {
    form: {
        layout: 'inline'  // Inline layout, form items displayed in one line
    }
}

Label Left Alignment

js
const option = {
    form: {
        layout: 'horizontal',
        labelAlign: 'left',  // Label left alignment
        labelWidth: '125px'
    }
}

Label Top Alignment

js
const option = {
    form: {
        layout: 'vertical',
        labelAlign: 'top'  // Label at top
    }
}

Configure Layout (row)

  • Type: Object

  • Description: Configure form component layout, including spacing between components.

  • Default Value:

js
  {
      show: true,
      gutter: 0
  }

Configuration Examples

Set Grid Spacing

js
const option = {
    row: {
        gutter: 16  // Set grid spacing to 16px
    }
}

Responsive Spacing

js
const option = {
    row: {
        gutter: {
            xs: 8,   // <768px spacing 8px
            sm: 16,  // ≥768px spacing 16px
            md: 24,  // ≥992px spacing 24px
            lg: 32   // ≥1200px spacing 32px
        }
    }
}

Configure Submit Button (submitBtn)

  • Type: Object

  • Description: Configure submit button style and layout.

  • Default Value:

js
  {
      theme: 'primary',
      loading: false,
      disabled: false,
      innerText: 'Submit',
      show: true,
      col: undefined,
      click: undefined
  }

Hide the button by setting submitBtn=false or submitBtn.show=false

Configuration Examples

Basic Configuration

js
const option = {
    submitBtn: {
        innerText: 'Submit',
        theme: 'primary',
        show: true
    }
}

Custom Button Text and Style

js
const option = {
    submitBtn: {
        innerText: 'Save',
        theme: 'primary',
        size: 'large'
    }
}

Hide Submit Button

js
const option = {
    submitBtn: false  // or submitBtn: { show: false }
}

Custom Button Layout

js
const option = {
    submitBtn: {
        innerText: 'Submit',
        col: {
            span: 6,  // Button occupies 6 columns
            offset: 3  // Left offset 3 columns
        }
    }
}

Custom Submit Event

js
const option = {
    submitBtn: {
        innerText: 'Submit',
        click: (formData, fApi) => {
            console.log('Submit data:', formData)
            // Custom submit logic
            return false  // Return false to prevent default submission
        }
    }
}

Configure Reset Button (resetBtn)

  • Type: Object

  • Description: Configure reset button style and layout.

  • Default Value:

js
  {
      theme: 'default',
      loading: false,
      disabled: false,
      innerText: 'Reset',
      show: false,
      col: undefined,
      click: undefined
  }

Show the button by setting resetBtn=true or resetBtn.show=true

Configuration Examples

Show Reset Button

js
const option = {
    resetBtn: {
        show: true,
        innerText: 'Reset',
        theme: 'default'
    }
}

Custom Reset Button Style

js
const option = {
    resetBtn: {
        show: true,
        innerText: 'Clear',
        theme: 'light',
        size: 'large'
    }
}

Custom Reset Event

js
const option = {
    resetBtn: {
        show: true,
        innerText: 'Reset',
        click: (fApi) => {
            console.log('Reset form')
            // Custom reset logic
            fApi.resetFields()  // Reset form fields
        }
    }
}

Floating Hint Box (info)

  • Type: Object

  • Description: Configure component hint messages

  • Default Value:

js
  {
    // Hint message type, popover, tooltip
    type: "popover",
    placement: 'topLeft',
    icon: 'question-circle-o'
  }

Configure hint component properties in the info option

Configuration Examples

Using Popover Hint

js
const option = {
    info: {
        type: 'popover',
        placement: 'top-left',  // Options: 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right' | 'left' | 'left-top' | 'left-bottom' | 'right' | 'right-top' | 'right-bottom'
        icon: 'question-circle-o',
        content: 'This is field description'
    }
}

Using Tooltip Hint

js
const option = {
    info: {
        type: 'tooltip',
        placement: 'top',
        icon: 'question-circle-o',
        content: 'This is field description'
    }
}

Custom Hint Icon

js
const option = {
    info: {
        type: 'popover',
        placement: 'top-left',
        icon: 'error-circle-o',  // Custom icon
        content: 'Please fill in this field carefully'
    }
}

Disable Hint

js
const option = {
    info: false  // or info: { show: false }
}

Configure FormItem (wrap)

  • Type: Object

  • Description: Configure FormItem display settings, including field styles and layout.

  • Complete configuration items: FormItem_props

Configuration Examples

Global Label Width Setting

js
const option = {
    wrap: {
        labelWidth: '150px'  // Global label width
    }
}

Complete Configuration Example

js
const option = {
    // Form overall configuration
    form: {
        layout: 'vertical',
        labelAlign: 'right',
        labelWidth: '125px'
    },


// Grid layout configuration
    row: {
        gutter: 16
    },


// Submit button configuration
    submitBtn: {
        innerText: 'Submit',
        theme: 'primary',
        show: true
    },


// Reset button configuration
    resetBtn: {
        show: true,
        innerText: 'Reset',
        theme: 'default'
    },


// Hint message configuration
    info: {
        type: 'popover',
        placement: 'top-left',
        icon: 'question-circle-o'
    },


// FormItem configuration
    wrap: {
        labelWidth: '125px'
    }
}

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.