当前位置:网站首页>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 ...
边栏推荐
- Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
- Blender exchange group, welcome to the water group ~
- Node:504 error reporting
- Why can't win11 display seconds? How to solve the problem that win11 time does not display seconds?
- Embedded development: how to choose the right RTOS for the project?
- 如何实现横版游戏中角色的移动控制
- [azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process
- PDF文档签名指南
- An in-depth understanding of fp/fn/precision/recall
- null == undefined
猜你喜欢
Ternary expressions, generative expressions, anonymous functions
Latest Android advanced interview questions summary, Android interview questions and answers
Jerry's manual matching method [chapter]
cv2.resize函数报错:error: (-215:Assertion failed) func != 0 in function ‘cv::hal::resize‘
What if the win11u disk does not display? Solution to failure of win11 plug-in USB flash disk
Ad domain group policy management
ByteDance senior engineer interview, easy to get started, fluent
三元表达式、各生成式、匿名函数
Anti climbing killer
The maximum number of meetings you can attend [greedy + priority queue]
随机推荐
2022 how to evaluate and select low code development platforms?
Use blocconsumer to build responsive components and monitor status at the same time
OpenGL job coordinate system
648. Word replacement
【Azure微服务 Service Fabric 】在SF节点中开启Performance Monitor及设置抓取进程的方式
Paint basic graphics with custompaint
What is the difference between the three values of null Nan undefined in JS
Pdf document signature Guide
Attitude estimation (complementary filtering)
Ad domain group policy management
[colmap] sparse reconstruction is converted to mvsnet format input
如何选择合适的自动化测试工具?
Use partial derivatives to display normals in unity
The latest Android interview collection, Android video extraction audio
[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)
DBSync新增对MongoDB、ES的支持
Code of "digital image processing principle and Practice (matlab version)" part2[easy to understand]
Jerry's power on automatic pairing [chapter]
客户案例|华律网,通过观测云大幅缩短故障定位时间
Reinforcement learning - learning notes 9 | multi step TD target