当前位置:网站首页>Change password, confirm password verification antd
Change password, confirm password verification antd
2022-07-28 13:13:00 【Pig Xiaoyong】

Code implementation
<Form ref={
form => this.form = form} onFinish={
this.handleOk} initialValues={
{
id }}>
<FormElement type="hidden" name="id" />
<FormElement
label=" New password "
type="password"
name="password"
required
rules={
[{
pattern:
/^(?![^a-zA-Z]+$)(?!\\D+$).{8,16}$/,
message: "8-16 Bit character , Must include letters and numbers ",
}]}
/>
<FormElement
label=" Confirm the password "
type="password"
name="reNewPassword"
dependencies={
['password']}
required
rules={
[
({
getFieldValue }) => ({
validator(rule, value) {
if (!value || getFieldValue('password') === value) {
return Promise.resolve();
}
return Promise.reject(' The new password is different from confirming the new password !');
},
}),
]}
/>
</Form>
Knowledge point 1 : dependencies

Use... When there is a dependency between fields . If a field is set dependencies attribute . When the fields it depends on are updated , This field will automatically trigger the update and verification . A common scene , It's about registering user forms “ password ” And “ Confirm the password ” Field .“ Confirm the password ” Verification depends on “ password ” Field , Set up dependencies after ,“ password ” Field update will trigger again “ Check the password ” The verification logic of .
Knowledge point two : getFieldValue

Knowledge point three :validator

Customize validator There is no effect
This is because of your validator There are errors that lead to callback It didn't work out to . You can choose to go through async Return to one promise Or use try…catch Error trapping :
validator: async (rule, value) => {
throw new Error('Something wrong!');
}
// or
validator(rule, value, callback) => {
try {
throw new Error('Something wrong!');
} catch (err) {
callback(err);
}
}
边栏推荐
- Shenwenbo, researcher of the Hundred Talents Program of Zhejiang University: kernel security in the container scenario
- Android engineers, how to use kotlin to provide productivity?
- Qt 信号和槽机制( 详解 )
- Fundamentals of machine learning - principal component analysis pca-16
- Kotlin是如何帮助你避免内存泄漏的?
- Flexpro software: measurement data analysis in production, research and development
- Interview must ask, focus! Tell me about the Android application startup process and its source code?
- [embedded C foundation] Part 5: original code / inverse code / complement code
- [basic teaching of Bi design] detailed explanation of OLED screen use - single chip microcomputer Internet of things
- Installation and reinstallation of win11 system graphic version tutorial
猜你喜欢

The essence of enterprise Digitalization

Dimming and color matching cool light touch chip-dlt8ma12ts-jericho

机器学习基础-集成学习-13

How to open the power saving mode of win11 system computer

Definition of option basis

BiliBili Yang Zhou: above efficiency, efficient delivery
![[basic teaching of Bi design] detailed explanation of OLED screen use - single chip microcomputer Internet of things](/img/76/820d4e357206f936b33da92a5e2b5b.png)
[basic teaching of Bi design] detailed explanation of OLED screen use - single chip microcomputer Internet of things

Smart touch screen LCD bathroom mirror light touch chip-dlt8t02s-jericho
![[Bi design teaching] STM32 and FreeRTOS realize low power consumption](/img/2b/3af85135e08599aaa425698c0e83aa.png)
[Bi design teaching] STM32 and FreeRTOS realize low power consumption

How to use databricks for data analysis on tidb cloud | tidb cloud User Guide
随机推荐
Black cat takes you to learn EMMC Protocol Part 26: hardware reset operation of EMMC (h/w reset)
如何在 TiDB Cloud 上使用 Databricks 进行数据分析 | TiDB Cloud 使用指南
机器学习基础-集成学习-13
[Bi design teaching] STM32 and FreeRTOS realize low power consumption
Summary: golang's ide:vscode usage
Margin calculation
[graduation design] oscilloscope design and Implementation Based on STM32 - single chip microcomputer Internet of things
Databinding+livedata can easily realize skin changing without restart
【嵌入式C基础】第8篇:C语言数组讲解
机器学习基础-决策树-12
FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be depreca
Pointnet++ Chinese Translation
子线程更新UI全解
Why neural networks are ineffective?
Interview must ask, focus! Tell me about the Android application startup process and its source code?
Black cat takes you to learn UFS agreement part 2: Interpretation of UFS related terms
Android工程师,如何使用Kotlin提供生产力?
What if the right button of win11 start menu doesn't respond
机器学习基础-支持向量机 SVM-17
LeetCode每日一题(2196. Create Binary Tree From Descriptions)