当前位置:网站首页>Add get disabled for RC form
Add get disabled for RC form
2022-07-07 22:18:00 【Belden wind】
background
In the use of ant Form time , When we need to pass the verification , Button is disabled , however Form Did not provide us with onDisable Methods , What shall I do? ?

terms of settlement
adopt onValuesChange When an validate
const [disabled, setDisabled] = useState(false);// Default inspection failed
const fieldDisabledRef = useRef({
});
const required = ['languages'];// All fields to be verified
const valueChange = changeValue => {
if (!formRef.current) {
return;
}
const values = formRef.current.getFieldsValue();
localStorage.setItem(`${
ID}_skill_info`, JSON.stringify(values));
const changeValueKeys = Object.keys(changeValue);
formRef.current.validateFields(changeValueKeys, (v, error) => {
changeValueKeys.forEach(key => {
if (error && error[key]) {
fieldDisabledRef.current[key] = true;
} else {
fieldDisabledRef.current[key] = false;
}
});
const keys = Object.keys(values);
let disabled = false;
keys.forEach(key => {
const disabledData = fieldDisabledRef.current[key];
if (disabledData === true || disabledData === undefined) {
disabled = true;
}
});
setDisabled(disabled);
});
};
useEffect(() => {
if (formRef.current) {
const data = Object.entries(initObj).reduce((result, [key, value]) => {
if (Array.isArray(value)) {
if (value.length || !required.includes(key)) {
result[key] = value;
}
return result;
}
if (value || !required.includes(key)) {
result[key] = value;
}
}, {
});
formRef.current.setFieldsValue(data);
}
}, [initObj]);
<Form
ref={
formRef}
layout="vertical"
onValuesChange={
valueChange}
initialValues={
...}
>
...
</Form>
That's it , Sometimes it's so simple to change your mind ...
边栏推荐
- Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
- Two kinds of updates lost and Solutions
- An in-depth understanding of fp/fn/precision/recall
- Song list 11111
- Redis - basic use (key, string, list, set, Zset, hash, geo, bitmap, hyperloglog, transaction)
- QT compile IOT management platform 39 alarm linkage
- Debugging and handling the problem of jamming for about 30s during SSH login
- Solve the problem of uni in uni app Request sent a post request without response.
- Remember that a development is encountered in the pit of origin string sorting
- Jerry's power on automatic pairing [chapter]
猜你喜欢

L2: current situation, prospects and pain points of ZK Rollup
![[JDBC Part 1] overview, get connection, CRUD](/img/53/d79f29f102c81c9b0b7b439c78603b.png)
[JDBC Part 1] overview, get connection, CRUD

Automatic classification of defective photovoltaic module cells in electronic images

Why can't win11 display seconds? How to solve the problem that win11 time does not display seconds?

The function is really powerful!

应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设

Crawler (17) - Interview (2) | crawler interview question bank

ByteDance Android interview, summary of knowledge points + analysis of interview questions

The whole network "chases" Zhong Xuegao

How to realize the movement control of characters in horizontal game
随机推荐
operator
Codemail auto collation code of visual studio plug-in
Matplotlib drawing interface settings
Embedded development: how to choose the right RTOS for the project?
建立自己的网站(18)
How to write an augmented matrix into TXT file
Win11时间怎么显示星期几?Win11怎么显示今天周几?
MIT6.S081-Lab9 FS [2021Fall]
【Azure微服务 Service Fabric 】在SF节点中开启Performance Monitor及设置抓取进程的方式
Paint basic graphics with custompaint
[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)
使用 CustomPaint 绘制基本图形
Use partial derivatives to display normals in unity
#DAYU200体验官#MPPT光伏发电项目 DAYU200、Hi3861、华为云IotDA
[开源] .Net ORM 访问 Firebird 数据库
[open source] Net ORM accessing Firebird database
TCP/IP 协议栈
Song list 11111
PKPM 2020软件安装包下载及安装教程
Jerry's test box configuration channel [chapter]