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

WEB Chinese Font Application Guide

Using fonts on the Web is both a fundamental skill...

MySQL UNION operator basic knowledge points

MySQL UNION Operator This tutorial introduces the...

Code for implementing simple arrow icon using div+CSS in HTML

In web design, we often use arrows as decoration ...

Basic reference types of JavaScript advanced programming

Table of contents 1. Date 2. RegExp 3. Original p...

How to implement property hijacking with JavaScript defineProperty

Table of contents Preface Descriptors Detailed ex...

How to quickly build an FTP file service using FileZilla

In order to facilitate the storage and access of ...

Using iframe techniques to obtain visitor QQ implementation ideas and sample code

Today at work, a friend I added temporarily asked ...

A question about border-radius value setting

Problem Record Today I was going to complete a sm...

Linux directory switching implementation code example

Switching files is a common operation in Linux. W...

Solution for converting to inline styles in CSS (css-inline)

Talk about the scene Send Email Embedding HTML in...

Jmeter connects to the database process diagram

1. Download the MySQL jdbc driver (mysql-connecto...

How to deploy code-server using docker

Pull the image # docker pull codercom/code-server...

5 tips for writing CSS to make your style more standardized

1. Arrange CSS in alphabetical order Not in alphab...

JS implements request dispatcher

Table of contents Abstraction and reuse Serial Se...