当前位置:网站首页>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 ...
边栏推荐
- #DAYU200体验官#MPPT光伏发电项目 DAYU200、Hi3861、华为云IotDA
- The latest Android interview collection, Android video extraction audio
- [advanced MySQL] index details (I): index data page structure
- Latest Android advanced interview questions summary, Android interview questions and answers
- How does win11 unblock the keyboard? Method of unlocking keyboard in win11
- [interview arrangement] 0211 game engine server
- How to quickly check whether the opening area ratio of steel mesh conforms to ipc7525
- The essence of analog Servlet
- QT compile IOT management platform 39 alarm linkage
- OpenGL job coordinate system
猜你喜欢

Win11如何解禁键盘?Win11解禁键盘的方法

Implementation method of data platform landing

Solve the problem of uni in uni app Request sent a post request without response.

Node:504 error reporting

【Azure微服务 Service Fabric 】在SF节点中开启Performance Monitor及设置抓取进程的方式

L2:ZK-Rollup的现状,前景和痛点

建立自己的网站(18)

The whole network "chases" Zhong Xuegao

Automatic classification of defective photovoltaic module cells in electronic images

使用 BlocConsumer 同时构建响应式组件和监听状态
随机推荐
Jerry's test box configuration channel [chapter]
Preparing for the interview and sharing experience
Jerry's about TWS pairing mode configuration [chapter]
Talk about relational database and serverless
戴森官方直营店免费造型服务现已开放预约 先锋科技诠释护发造型理念,助力消费者解锁多元闪耀造型
应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设
[open source] Net ORM accessing Firebird database
Navicat connect 2002 - can't connect to local MySQL server through socket '/var/lib/mysql/mysql Sock 'solve
怎样写一个增广矩阵到txt文件中
What is the difference between the three values of null Nan undefined in JS
Reinforcement learning - learning notes 8 | Q-learning
Win11U盘不显示怎么办?Win11插U盘没反应的解决方法
Implementation method of data platform landing
Paint basic graphics with custompaint
Matplotlib drawing interface settings
Welcome to CSDN markdown editor
Latest Android advanced interview questions summary, Android interview questions and answers
Jerry's about TWS channel configuration [chapter]
[interview arrangement] 0211 game engine server
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?