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

UDP DUP timeout UPD port status detection code example

I have written an example before, a simple UDP se...

MySQL sharding details

1. Business scenario introduction Suppose there i...

Example of how to implement value transfer between WeChat mini program pages

Passing values ​​between mini program pages Good ...

Analysis of the difference between absolute path and relative path in HTML

As shown in the figure: There are many files conne...

Tutorial diagram of using Jenkins for automated deployment under Windows

Today we will talk about how to use Jenkins+power...

Docker beginners' first exploration of common commands practice records

Before officially using Docker, let's first f...

Basic principles for compiling a website homepage

1. The organizational structure of the hypertext d...

Implementation of multiple instances of tomcat on a single machine

1. Introduction First of all, we need to answer a...

A few things you need to know about responsive layout

1. Introduction Responsive Web design allows a we...

Detailed explanation of how to monitor MySQL statements

Quick Reading Why do we need to monitor SQL state...

Docker Stack deployment method steps for web cluster

Docker is becoming more and more mature and its f...

Sample code for testing technology application based on Docker+Selenium Grid

Introduction to Selenium Grid Although some new f...

Analysis of the use of the MySQL database show processlist command

In actual project development, if we have a lot o...

Summary of commonly used time, date and conversion functions in Mysql

This article mainly summarizes some commonly used...