Antd+vue realizes the idea of ​​dynamic verification of circular attribute form

Antd+vue realizes the idea of ​​dynamic verification of circular attribute form

I hope to implement some properties of the query form to loop and verify the required items:

need:

1. Name, comparison item, and remarks are required. The default is one line. You can add multiple lines.

2. Dynamically request a comparison item list based on the name. When the name changes, clear the currently selected comparison item in that row

Idea: Divide the entire search into two forms and perform verification separately. One is a dynamically added loop form, and the other is a normal form dateForm

html

			<a-form :form="form" @keyup.enter.native='searchQuery'>
				<div class="dynamic-wrap">
					<div v-for="(item,index) in formList" :key="index">
						<a-row :gutter="24">
							<a-col :span="6">
								<a-form-item label="Name" :labelCol="{span: 7}" :wrapperCol="{span: 17}">
									<a-select placeholder='Please select a name'
									          v-decorator="[`equipment[${index}]`,{ initialValue: formList[index] ? formList[index].equipment : '', rules: [{ required: true, message: 'Please select equipment!' }]}]"
									          @change="(e)=>equipChange(e,index)">
										<a-select-option v-for='options in formList[index].eqpList' :key='options.name' :value='options.name'>
											{{ options.name }}
										</a-select-option>
									</a-select>
								</a-form-item>
							</a-col>
							<a-col :span="6">
								<a-form-item label="Comparison item" :labelCol="{span: 7}" :wrapperCol="{span: 17}">
									<a-select
										placeholder="Please select a comparison item"
										v-decorator="[`dataCode[${index}]`,{initialValue: formList[index] ? formList[index].dataCode : '',rules: [{ required: true, message: 'Please select the comparison item!' }]}]">
										<a-select-option v-for='option in formList[index].dataTypeList' :key='option.name' :value='option.name'>
											{{ option.name }}
										</a-select-option>
									</a-select>
								</a-form-item>
							</a-col>
							<a-col :span="6">
								<a-form-item label="Remarks" :labelCol="{span: 6}" :wrapperCol="{span: 18}">
									<a-input v-decorator="[`remark[${index}]`]" placeholder="Please enter remarks"></a-input>
								</a-form-item>
							</a-col>
							<a-col :span="2" style="padding-left: 0px">
								<a-form-item :labelCol="{span: 0}" :wrapperCol="{span: 24}">
									<template v-if="formList.length > 1">
										<a-icon type="delete" @click="removeRow(index)"/>
									</template>
								</a-form-item>
							</a-col>
						</a-row>
					</div>
				</div>
			</a-form>
 
			<a-form :form="dateForm" inline @keyup.enter.native='searchQuery'>
				<a-form-item label='Query date' :labelCol="{span: 8}" :wrapperCol="{span: 16}"
				             style="display: inline-block;width: 300px;">
					<a-date-picker
						style="width: 200px;"
						class='query-group-cust'
						v-decorator="['startTime', { rules: [{ required: true, message: 'Please select a start time!' }] }]"
						:disabled-date='disabledStartDate'
						format='YYYY-MM-DD'
						placeholder='Please select a start time'
						@change='handleStart($event)'
						@openChange='handleStartOpenChange'></a-date-picker>
				</a-form-item>
				<span :style="{ display: 'inline-block', width: '24px', textAlign: 'center' }">-</span>
				<a-form-item style="display: inline-block;width: 200px;">
					<a-date-picker
						style="width: 200px;"
						class='query-group-cust'
						v-decorator="['endTime', { rules: [{ required: true, message: 'Please select an end time!' }] }]"
						:disabled-date='disabledEndDate'
						format='YYYY-MM-DD'
						placeholder='Please select end time'
						@change='handleEnd($event)'
						:open='endOpen'
						@openChange='handleEndOpenChange'></a-date-picker>
				</a-form-item>
				<span style="margin-left: 10px">
				        <a-button type='primary' :disabled='loading' @click='searchQuery' icon='search'>Search</a-button>
				        <a-button type='primary' @click='searchReset' icon='search' style='margin-left:10px'>Reset</a-button>
				        <a-button type="primary" icon="plus" @click="addRow" style='margin-left:10px'>Add query conditions</a-button>
			        </span>
			</a-form>
			<p>The query condition is: {{searchData}}</p>

js

initForm() {
				// First request the device list and store it in eqpList // Initialize the form this.formList.push({
					equipment: '',
					dataCode: '',
					remark: '',
					eqpList: this.eqpList,
					dataTypeList: []
				})
			},
			// Delete a row handleRemove(index) {
				if (this.formList.length === 1) {
					return
				}
				this.formList.splice(index, 1)
			},
			// Add a new row handleAdd() {
				this.formList.push({
					equipment: '',
					dataCode: '',
					remark: '',
					eqpList: this.eqpList, // Can be obtained dynamically according to the interface. Here, it is easy to demonstrate and directly assigned dataTypeList: [], // Can be obtained dynamically according to the interface and associated according to the device })
			},
			equipChange(value, index) {
				// change value this.formList[index].equipment = value;
				//Synchronously update the comparison item list corresponding to the currently selected device this.handleEqpIdentity(value, index)
			},
			// Query the corresponding comparison item list according to the device handleEqpIdentity(value, index) {
				this.dataTypeList = []; // Clear dataTypeList
				this.formList[index].dataTypeList = []; // Clear the dataTypeList of the current row
				//Get the corresponding comparison item list according to the new equipment name getAction(this.url.getDataTypeList, {equipment: value})
					.then((res) => {
						if (res.success) {
							this.dataTypeList = res.result;
							this.formList[index].dataTypeList = this.dataTypeList;
							// this.formList[index].dataCode = ''; Directly assigning a value of null is invalid //You need to use getFieldValue, setFieldsValue
							let dataCode1Arr = this.form.getFieldValue('dataCode');
							if (dataCode1Arr.length !== 0) {
								dataCode1Arr[index] = ''
							}
							this.form.setFieldsValue({dataCode: dataCode1Arr})
						} else {
							this.$message.warning(res.message)
						}
					})
					.catch(() => {
						this.$message.error('Failed to obtain, please try again!')
					})
			},
// Click query searchQuery() {
				// Validate the loop form first const {form: {validateFields}} = this
				validateFields((error, values) => {
					if (!error) {
						this.dateForm.validateFields((dateErr, dateValues) => {
							//Revalidate the date search form dateValues.startTime = moment(dateValues.startTime).format('YYYY-MM-DD')
							dateValues.endTime = moment(dateValues.endTime).format('YYYY-MM-DD')
							if (!dateErr) {
								this.loading = true;
								let formData = Object.assign({}, dateValues);
								//Organize into the data structure required by the background // Loop form let searchArr = [];
								(values[`equipment`]).forEach((item, index) => {
									const obj = {
										equipment: item,
										remark: values[`remark`][index],
										dataCode: values[`dataCode`][index]
									}
									searchArr.push(obj);
 
								})
								// Date form if (!dateValues.startTime) {
									formData.startTime = moment(new Date()).format('YYYY-MM-DD')
								}
								formData.eqpInfoParamVoList = searchArr;
								this.searchData = JSON.parse(formData)
							  // Request interface }
						})
					}
				})
			},

This is the end of this article about antd vue's implementation of dynamic validation loop attribute form. For more related antd vue dynamic validation loop attribute form content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Antdesign-vue combined with sortablejs to achieve the function of dragging and sorting two tables
  • Detailed explanation of the friendly use of antdv examples in vue3.0
  • Antd-vue Table component adds Click event to click on a row of data tutorial
  • Antd vue table merges cells across rows and customizes content instances
  • antd vue refresh retains the current page route, retains the selected menu, retains the menu selection operation
  • Method for implementing the right-click menu in the Table component row in Vue (based on vue + AntDesign)

<<:  5 Commands to Use the Calculator in Linux Command Line

>>:  Detailed tutorial on deploying SpringBoot + Vue project to Linux server

Recommend

A Brief Discussion on the Navigation Window in Iframe Web Pages

A Brief Discussion on the Navigation Window in If...

The One-Hand Rule of WEB2.0

<br />My previous article about CSS was not ...

Introduction to the usage of props in Vue

Preface: In Vue, props can be used to connect ori...

Vue implements the right slide-out layer animation

This article example shares the specific code of ...

React implements multi-component value transfer function through conetxt

The effect of this function is similar to vue的pro...

Do not start CSS pseudo-class names with numbers

When newbies develop div+css, they need to name t...

MySQL 5.7.17 winx64 installation and configuration method graphic tutorial

Windows installation mysql-5.7.17-winx64.zip meth...

Docker connects to a container through a port

Docker container connection 1. Network port mappi...

WeChat Mini Program Lottery Number Generator

This article shares the specific code of the WeCh...

Mysql experiment: using explain to analyze the trend of indexes

Overview Indexing is a skill that must be mastere...

MySQL 5.7.27 installation and configuration method graphic tutorial

MySQL 5.7.27 detailed download, installation and ...

Mycli is a must-have tool for MySQL command line enthusiasts

mycli MyCLI is a command line interface for MySQL...

CentOS 7.x docker uses overlay2 storage method

Edit /etc/docker/daemon.json and add the followin...

What are the new CSS :where and :is pseudo-class functions?

What are :is and :where? :is() and :where() are p...