当前位置:网站首页>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 ...
边栏推荐
- 海外代理推荐
- Google SEO external chain backlinks research tool recommendation
- Jerry's fast pairing does not support canceling pairing [article]
- Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
- Use json Stringify() to realize deep copy, be careful, there may be a huge hole
- Reptile combat (VII): pictures of the king of reptiles' heroes
- How to realize the movement control of characters in horizontal game
- Preparing for the interview and sharing experience
- Kirin Xin'an operating system derivative solution | storage multipath management system, effectively improving the reliability of data transmission
- 反爬通杀神器
猜你喜欢

Win11U盘不显示怎么办?Win11插U盘没反应的解决方法

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

#DAYU200体验官#MPPT光伏发电项目 DAYU200、Hi3861、华为云IotDA

海外代理推荐

客户案例|华律网,通过观测云大幅缩短故障定位时间

Jenkins user rights management

The whole network "chases" Zhong Xuegao

An in-depth understanding of fp/fn/precision/recall

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

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?
随机推荐
It's worth seeing. Interview sites and interview skills
Dry goods sharing | devaxpress v22.1 original help document download collection
海外代理推荐
如何实现横版游戏中角色的移动控制
Use json Stringify() to realize deep copy, be careful, there may be a huge hole
Leetcode SQL first day
Write in front -- Talking about program development
South China x99 platform chicken blood tutorial
双塔模型的最强出装,谷歌又开始玩起“老古董”了?
Tsconfig of typescript TS basics JSON configuration options
SAR影像质量评估
OpenGL configuration vs2019
Have you ever been confused? Once a test / development programmer, ignorant gadget C bird upgrade
NVR hard disk video recorder is connected to easycvr through the national standard gb28181 protocol. What is the reason why the device channel information is not displayed?
Index summary (assault version)
Embedded development: how to choose the right RTOS for the project?
L2:ZK-Rollup的现状,前景和痛点
Relationship between URL and URI
用语雀写文章了,功能真心强大!
[开源] .Net ORM 访问 Firebird 数据库