当前位置:网站首页>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 ...
边栏推荐
- What is the difference between the three values of null Nan undefined in JS
- [JDBC Part 1] overview, get connection, CRUD
- 使用 CustomPaint 绘制基本图形
- 100million single men and women "online dating", supporting 13billion IPOs
- QT compile IOT management platform 39 alarm linkage
- [advanced MySQL] index details (I): index data page structure
- OpenGL homework - Hello, triangle
- How polardb-x does distributed database hotspot analysis
- Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
- Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
猜你喜欢

How to make agile digital transformation strategy for manufacturing enterprises

L2: current situation, prospects and pain points of ZK Rollup

Customer case | China law network, through observing the cloud, greatly shortens the time of fault location

operator
Latest Android advanced interview questions summary, Android interview questions and answers

Dry goods sharing | devaxpress v22.1 original help document download collection

Two kinds of updates lost and Solutions

NVR硬盘录像机通过国标GB28181协议接入EasyCVR,设备通道信息不显示是什么原因?

Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘

The whole network "chases" Zhong Xuegao
随机推荐
MIT6.S081-Lab9 FS [2021Fall]
Use json Stringify() to realize deep copy, be careful, there may be a huge hole
[colmap] sparse reconstruction is converted to mvsnet format input
TCP/IP 协议栈
Why can't win11 display seconds? How to solve the problem that win11 time does not display seconds?
Main functions of OS, Sys and random Standard Libraries
Jerry's about TWS channel configuration [chapter]
Crawler (17) - Interview (2) | crawler interview question bank
建立自己的网站(18)
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?
The essence of analog Servlet
Jerry's about TWS pairing mode configuration [chapter]
[开源] .Net ORM 访问 Firebird 数据库
【colmap】稀疏重建转为MVSNet格式输入
Typescript TS basic knowledge type declaration
Kirin Xin'an operating system derivative solution | storage multipath management system, effectively improving the reliability of data transmission
How does win11 unblock the keyboard? Method of unlocking keyboard in win11
Paint basic graphics with custompaint
SAR影像质量评估
为什么Win11不能显示秒数?Win11时间不显示秒怎么解决?