当前位置:网站首页>Supplement to fusionui form component
Supplement to fusionui form component
2022-06-23 21:29:00 【Swing a knife North】
In the previous article, we introduced fusionUI The use of form components , There are some things that are not added here , If our form is filled in the project , Some values need to be manipulated in real time , Or get the value of some input items in real time , How to operate ? There are the following centralized schemes , Listen for change event , Change the component to get the changed value .
There's another way , yes fusion For us , We can approach Form The form passes a parameter , This parameter was not improved in the previous article , Here's a supplement , What are the parameters ? That's it value Properties and onChange function ,chang Function to listen for changes in each element of the form , And then reassign it to value:
import * as React from 'react';
import {
Avatar,
Card,
Tab,
ResponsiveGrid,
Table,
Typography,
Upload,
Button,
Form,
Input,
Message,
Box,
Radio,
Dialog,
Icon,
} from '@alifd/next';
import styles from './index.module.css';
const { useState, useEffect } = React;
const { Cell } = ResponsiveGrid;
const FormItem = Form.Item;
const SettingSystemBlock = (props) => {
const [initialized, setInitialize] = useState(false);
const [preview, setPreview] = useState(true);
const [postData, setValue] = useState({});
useEffect(() => {
setInitialize(true);
}, [initialized]);
const formChange = (values) => {
setValue(values);
};
const onSubmit = (values, errors) => {
console.log('values:', values);
console.log('postData:', postData);
};
return (
<Card free>
<Card.Content className={styles.settingPersonBlock}>
<Box className={styles.baseSettingContainer}>
<Form
isPreview={preview}
className={styles.baseSetting}
value={postData}
labelAlign="top"
onChange={formChange}
responsive
>
<FormItem label=" Company cover " colSpan={12}>
<ResponsiveGrid gap={10}>
<Cell colSpan={2}>
<Avatar
src={postData.image&&`http://alfuser.quchangguan.cn/${postData.image[0].url}`}
shape="circle" size={64} icon="account" />
</Cell>
<Cell colSpan={10} className={styles.changeLogo}>
<Box spacing={12}>
<FormItem>
<Upload
limit={1}
formatter={(res) => {
return {
success: true,
url: res.data.result.mid,
};
}}
action="/api/alf/image/upload2"
// name="image"
>
<Button className={styles.uploadButton} type="primary">
Update company logo
</Button>
</Upload>
</FormItem>
<Box>
<p>* logo Try to upload more than 80px*80px, But don't be too big .</p>
<p>* Please upload a double image to ensure clarity </p>
</Box>
</Box>
</Cell>
</ResponsiveGrid>
</FormItem>
<FormItem label=" Corporate name " required requiredMessage=" Required " colSpan={12}>
<Input placeholder=" Please enter the company name " name="companyName" />
</FormItem>
<FormItem label=" When the company was founded " required requiredMessage=" Required " colSpan={12}>
<Input placeholder=" Please enter the company creation time " name="createAt" />
</FormItem>
<FormItem label=" Company number " required requiredMessage=" Required " colSpan={12}>
<Input placeholder=" Please enter company number " name="companyId" />
</FormItem>
{preview ? (
<FormItem colSpan={12}>
<Button
style={{ marginRight: '20px' }}
type="primary"
onClick={() => {
setPreview(false);
}}
>
edit
</Button>
</FormItem>
) : (
<FormItem colSpan={12}>
<Button
style={{ marginRight: '20px' }}
type="primary"
onClick={() => {
setPreview(true);
}}
>
Cancel
</Button>
<Form.Submit type="primary" onClick={onSubmit} >
preservation
</Form.Submit>
</FormItem>
)}
</Form>
</Box>
</Card.Content>
</Card>
);
};
export default SettingSystemBlock;
In the code , We monitored postdata Of image attribute , When the picture component in the form is uploaded ,chang perform ,postdata change , Real time picture display .
such , When triggered submit When an event is , We can get the value of the form from the parameter of the function , You can also get it from postdata Get value .
The above is fusionUI Supplement to upload components , I hope it helped you .
边栏推荐
- ES6 promise detailed sewing Red Treasure Book Introduction to ES6 standard
- Using asp Net core MVC framework for building web applications
- Global and Chinese markets for e-cigarettes and tobacco vapors 2022-2028: Research Report on technology, participants, trends, market size and share
- What can RFID fixed assets management system bring to enterprises?
- [tutorial] Tencent lightweight cloud builds an online customer service chat system
- What are the processing methods for PPT pictures
- ZABBIX custom monitoring item (server monitoring)
- How to make a label for an electric fan
- Whether the offsetwidth includes scroll bars
- 我在深圳,到哪里开户比较好?在线开户安全么?
猜你喜欢

How PMO uses two dimensions for performance appraisal

I am 30 years old, no longer young, and have nothing

Steps for formulating the project PMO strategic plan

New SQL syntax quick manual!

Lightweight, dynamic and smooth listening, hero earphone hands-on experience, can really create

Facing the problem of lock waiting, how to realize the second level positioning and analysis of data warehouse

How to view the role of PMO in agile organizations?

Gradle asked seven times. You should know that~

How does PMO select and train project managers?
Application of JDBC in performance test
随机推荐
Is it safe to open an account for flush stock?
股票开户要找谁?网上开户安全么?
Process crash does not generate dump. Configure localdumps
New SQL syntax quick manual!
2021-12-25: given a string s consisting only of 0 and 1, assume that the subscript is from
SAP Migo mobile type 311 attempts to determine the batch, and the system reports an error -batch determination not Po
Use Tencent cloud lightweight application server to build an unlimited network disk -zpan building tutorial
How to reduce snapshots
同花顺开户是安全的吗?
A detailed discussion on the use guide of network Swiss Army knife nmap
Summary of multiple methods for obtaining the last element of JS array
Advantages of token mechanism over cookie mechanism
Overview of digital circuits
Chrome extension development Chinese tutorial-1
On line project LAN on-line software use ----phpstudy
Global and Chinese market of cloud billing services 2022-2028: Research Report on technology, participants, trends, market size and share
How to use smart cloud disk service differences between local disk service and cloud disk service
Spingboot reads the parameter values in the YML configuration file
Full text search of MySQL
JS how to get the current local date