当前位置:网站首页>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 ...
边栏推荐
- Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
- Codemail auto collation code of visual studio plug-in
- [colmap] sparse reconstruction is converted to mvsnet format input
- 嵌入式开发:如何为项目选择合适的RTOS?
- 【Azure微服务 Service Fabric 】如何转移Service Fabric集群中的种子节点(Seed Node)
- [interview arrangement] 0211 game engine server
- NVR硬盘录像机通过国标GB28181协议接入EasyCVR,设备通道信息不显示是什么原因?
- 强化学习-学习笔记9 | Multi-Step-TD-Target
- DBSync新增对MongoDB、ES的支持
- [advanced MySQL] index details (I): index data page structure
猜你喜欢
OpenGL configuration vs2019
Build your own website (18)
DNS series (I): why does the updated DNS record not take effect?
Px4 autonomous flight
Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
Debugging and handling the problem of jamming for about 30s during SSH login
TCP/IP 协议栈
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
Win11U盘不显示怎么办?Win11插U盘没反应的解决方法
Navicat connect 2002 - can't connect to local MySQL server through socket '/var/lib/mysql/mysql Sock 'solve
随机推荐
PKPM 2020 software installation package download and installation tutorial
嵌入式开发:如何为项目选择合适的RTOS?
Blender exchange group, welcome to the water group ~
Validutil, "Rethinking the setting of semi supervised learning on graphs"
Dbsync adds support for mongodb and ES
Can I open a stock account directly online now? Is it safe?
ByteDance Android interview, summary of knowledge points + analysis of interview questions
Open source OA development platform: contract management user manual
The whole network "chases" Zhong Xuegao
L'enregistreur de disque dur NVR est connecté à easycvr par le Protocole GB 28181. Quelle est la raison pour laquelle l'information sur le canal de l'appareil n'est pas affichée?
Jerry's test box configuration channel [chapter]
How to write an augmented matrix into TXT file
如何实现横版游戏中角色的移动控制
谈谈制造企业如何制定敏捷的数字化转型策略
解决uni-app中uni.request发送POST请求没有反应。
Embedded development: how to choose the right RTOS for the project?
How to integrate Google APIs with Google's application system (1) -introduction to Google APIs
应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设
[azure microservice service fabric] how to transfer seed nodes in the service fabric cluster
How to choose the appropriate automated testing tools?