Skip to content

MakingForm

A form designer component that visualizes form pages

Code Demonstration

Basic Usage

vue
<template>
  <fm-making-form 
  	ref="makingform" 
    style="height: 700px;"
    preview 
    generate-code 
    generate-json
  >
  </fm-making-form>
</template>

notice

The default height is 100% of the height of the parent element, but if the parent element does not specify a height, the form designer can specify a specific height.

Click to see the effect

Effect Picture

Customize Action Buttons

vue
<template>
  <fm-making-form 
    ref="makingform" 
    style="height: 700px;" 
  >
    <template slot="action">
      <!-- Customize the operation area slot -->
      <el-button type="text" icon="el-icon-upload">Save</el-button>
    </template>
  </fm-making-form>
</template>
Click to see the effect

Effect Picture

Designer Left Field Configuration

vue
<template>
  <fm-making-form 
    ref="makingform" 
    style="height: 700px;"
    :basic-fields="['input', 'textarea']"
    :advance-fields="['blank', 'fileupload']"
    :layout-fields="['grid']"
  >
  </fm-making-form>
</template>
Click to see the effect

Effect Picture

Saving Form JSON

vue
<template>
    <fm-making-form 
      ref="makingform" 
      style="height: 700px;" 
      preview 
      generate-code 
      generate-json
    >
      <template slot="action">
        <el-button type="text" icon="el-icon-upload" @click="handleSave">Save</el-button>
      </template>
    </fm-making-form>
</template>

<script>
export default {
  methods: {
    handleSave () {
      const json = this.$refs.makingform.getJSON()

      this.$alert(json, 'save successfully!')
    }
  }
}
</script>
Click to see the effect

Effect Picture

Importing Form JSON

Import the designed form JSON Schema into the new designer.

vue
<template>
    <fm-making-form 
      ref="makingform" 
      style="height: 700px;" 
      preview 
      generate-code 
      generate-json
      @ready="handleFormReady"
    >
    </fm-making-form>
</template>

<script>
export default {
  methods: {
    handleFormReady () {
      this.$refs.makingform.setJSON(
        // Form JSON object
      )
    }
  }
}
</script>

notice

We need to import the json after the designer is initialized and do that in the ready event

Initialize the Form Stylesheet

vue
<template>
  <fm-making-form ref="makingForm" clearable upload preview generate-code generate-json
    :global-config="globalConfig"
  >
  </fm-making-form>
</template>

<script>
export default {
  data() {
    return {
      globalConfig: {
        // The preset styles of the form can be put into the designer
        styleSheets: '.a .el-form-item__label{color: red;}'
      }
    }
  }
}
</script>

notice

The designer will automatically parse the configured stylesheet when it is initialized, extract the first-class Class name, and configure it in a Custom Class.

Click to see the effect

Effect Picture

Initialize the Form Data Source

Form data sources can be predefined as follows:

vue
<template>
  <fm-making-form ref="makingForm" clearable upload preview generate-code generate-json
    :global-config="globalConfig"
  >
  </fm-making-form>
</template>

<script>
export default {
  data() {
    return {
      globalConfig: {
        dataSource: [
          {
            key: 'getoptions', // Unique value specified
            name: 'Get Options', // Data source name, unique value
            url: 'http://tools-server.making.link/api/new/options', // Request interface address
            method: 'GET',
            auto: true, // Whether to send a request on form initialization
            responseFunc: 'return res.data', // Data manipulation function contents
            headers: {}, // Data request header, optional
            params: {}, // Data request parameter, optional, (query parameter)
          }
        ]
      }
    }
  }
}
</script>
Click to see the effect

Effect Picture

Form Field Default Configuration

The default properties of the fields in the designer can be configured via field-config.

vue
<template>
  <fm-making-form ref="makingForm" clearable upload preview generate-code generate-json
    :field-config="fieldConfig"
  >
  </fm-making-form>
</template>

<script>
export default {
  data() {
    return {
      fieldConfig: [
        {
          type: 'fileupload',
          options: {
            // Configure the upload component address
            domain: 'http://tcdn.form.making.link/',
            action: 'http://tools-server.making.link/api/transfer',
          }
        },
        {
          type: 'select',
          options: {
            // Configure static option data for the drop-down box component
            options: [
              {value: '1111'},
              {value: '2222'},
              {value: '3333'}
            ]
          }
        }
      ]
    }
  }
}
</script>

For more field configurable property, you can refer toField Configurable Property.

Field identity drop-down select binding

Sometimes when we design a form, the data field identity is already specified, which can be passed to the designer via field-models, and the field binding can be selected at design time.

See
<template>
  <fm-making-form 
    ref="makingForm"
    :field-models="fieldModels"
  >
  </fm-making-form>
</template>

<script>
export default {
  data() {
    return {
      fieldModels: [{
        fieldId: 'userId'
      },
      {
        fieldId: 'userName',
        fieldLabel: 'User Name'
      }]
    }
  },
}
</script>
Click to see the effect

Effect Picture

Field property Custom Extensions

In the field property configuration, we can introduce our own extended configuration through the slot.

vue
<fm-making-form>
  <template #widgetConfig="{type, data, customProps}">
    <el-form-item v-if="type === 'button'" label="Loading">
      <el-switch v-model="customProps.loading"></el-switch>
    </el-form-item>
  </template>
</fm-making-form>

Here we are able to configure the properties of the field via the widgetConfig slot and receive the type:(field type) data:(field json data) customProps:(field custom extended properties for binding configuration items) parameter.

Click to see the effect

Effect Picture

API

Property

PropertyDescriptionTypeDefaultVersion
previewPreview operationbooleanfalse
generate-jsonGenerate json operationbooleanfalse
generate-codeGenerate code operationbooleanfalse
clearableClear operationbooleanfalse
uploadImport json operationbooleanfalse
basic-fields Basic field configuration,
refer to Field Description-Basic Field
array-
advance-fieldsAdvanced field configuration,
refer to Field Description-Advanced Field
array-
layout-fieldsLayout field configuration,
refer to Field Description-Layout Field
array-
collection-fieldsCollection field configuration,
refer to Field Description-Collection Field
array-1.5.0
custom-fieldsCustom field configurationarray-
global-configThe form initializes global configuration,
refer to Global Config Options
object-1.3.0
field-configFor more field configurable property, you can refer to Field Configurable Propertyarray-1.3.6
name设计器名称1.4.0
cacheYou can configure the name property to differentiate whether json is cached to the browserbooleanfalse1.4.0
json-templatesTemplate library configuration;
{
  title: 'Chinese template name',
  enTitle: 'English template name',
  json: 'Template json',
  url: 'Template preview thumbnail'
}
array[]1.4.0
init-from-templateWhether to enable selection from the template library during initializationbooleanfalse1.4.0
field-modelsField identity configuration, which provides a drop-down binding for designer field identity.
{
  fieldId: Bind field identification,
  fieldLabel: Name of display
}
array[]1.4.1
panelLeft panel default display type:
field : Component Library Panel
outline : Outline Panel
stringfield1.4.5

Slot

nameDescriptionVersion
actionDesigner header action button customization area
widgetConfig
widgetconfig
Field attributes custom extension area, please refer to Field property Custom Extensions
1.4.5
1.5.2

Method

The MakingForm instance is retrieved and the instance methods are called with this.$refs

Method NameDescriptionParameterVersion
getJSONGet the json data for the designer-
getHtmlGet the code generated by the designer that can be used directly --
setJSONSet the json data for the designer(value) json data fetched by the designer
clearClear-
handleUndoUndo-
handleRedoRedo-
setSelectSet the currently selected component by the designer(field) Field ID1.3.6
getFormModelsGets a list of form field structures-1.5.3
generatePreviewQrcode生成手机预览二维码 (url) 二维码地址1.5.5

Events

Event NameDescriptionCallback parametersVersion
readyThe designer is initialized-1.2.18
preview表单预览 (json) 表单JSON配置1.5.5

Global Config Options

ParameterDescriptionTypeDefaultVersion
uiComponent libraries used by the form,
Element: element
Ant Design: antd
stringelement1.3.0
widthForm widthstring100%1.3.0
customClassCustom stylesheet class namesstring-1.3.0
styleSheetsRefer toInitialize the Form Stylesheetstring-1.3.0
dataSourceRefer toInitialize the Form Data Sourcearray-1.3.0
eventScriptForm eventsarray-1.3.0
platformPlatform, optional pc, pad, mobilestring-1.3.4