当前位置:网站首页>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 ...
边栏推荐
- 三元表达式、各生成式、匿名函数
- Jerry's power on automatic pairing [chapter]
- L2: current situation, prospects and pain points of ZK Rollup
- 为什么Win11不能显示秒数?Win11时间不显示秒怎么解决?
- 双塔模型的最强出装,谷歌又开始玩起“老古董”了?
- 【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
- Win11游戏模式怎么开启?Win11开启游戏模式的方法
- 你可曾迷茫?曾经的测试/开发程序员,懵懂的小菜C鸟升级......
- OpenGL configure assimp
- 【Azure微服务 Service Fabric 】如何转移Service Fabric集群中的种子节点(Seed Node)
猜你喜欢

如何实现横版游戏中角色的移动控制

Win11如何解禁键盘?Win11解禁键盘的方法
![[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)](/img/35/1bb21c100980eb1075dbbcb922e181.png)
[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)

Dayu200 experience officer MPPT photovoltaic power generation project dayu200, hi3861, Huawei cloud iotda
![Restapi version control strategy [eolink translation]](/img/65/decbc158f467ab8c8923c5947af535.png)
Restapi version control strategy [eolink translation]

Jenkins user rights management
Talk about relational database and serverless

How to turn on win11 game mode? How to turn on game mode in win11

OpenGL configuration vs2019

operator
随机推荐
SAR影像质量评估
[open source] Net ORM accessing Firebird database
Display optimization when the resolution of easycvr configuration center video recording plan page is adjusted
强化学习-学习笔记9 | Multi-Step-TD-Target
How to choose the appropriate automated testing tools?
Dayu200 experience officer MPPT photovoltaic power generation project dayu200, hi3861, Huawei cloud iotda
海外代理推荐
Main functions of OS, Sys and random Standard Libraries
How to realize the movement control of characters in horizontal game
How does win11 unblock the keyboard? Method of unlocking keyboard in win11
Kaggle-Titanic
cv2.resize函数报错:error: (-215:Assertion failed) func != 0 in function ‘cv::hal::resize‘
Reinforcement learning - learning notes 9 | multi step TD target
Build your own website (18)
The difference between NPM uninstall and RM direct deletion
反爬通杀神器
Latest Android advanced interview questions summary, Android interview questions and answers
PDF文档签名指南
OpenGL job coordinate system
使用 CustomPaint 绘制基本图形