当前位置:网站首页>Antd mobile form validation RC form usage
Antd mobile form validation RC form usage
2022-07-21 03:22:00 【cc_ King】
List of articles
The most basic use
cnpm i rc-form -S
import React, {
Component } from 'react'
import {
InputItem } from 'antd-mobile'
import {
createForm } from 'rc-form'
class Login extends Component {
/** 3. * Customized verification method * @param {Object} rule You can get the verification object in it (getFieldProps The first parameter of corresponds to ) * @param {String} value Current value of input box * @param {Function} callback Trigger the failed callback function ( Return error message ) */
validatorAccount = (rule, value, callback) => {
callback(new Error(' Error message !'))
}
render() {
// 1. Here we need to use two methods :
// Method 1 : getFieldProps : Set the validation mode
// Method 2 : getFieldError : Error handling
const {
getFieldProps, getFieldError } = this.props.form;
return (
<div className="login">
<div className="body">
<div className="login-account">
<InputItem
name="account"
clear
// 2. Binding validation method ( The first parameter is understood as key value )
{
...getFieldProps('account', {
rules: [{
"validator": this.validatorAccount }]
})
}
// 3. icon Error message ( Add a small fork after the input box , Indicates that there is a problem with this input )
error={
!!getFieldError('account')}
// 4. 3 Produced icon Callback function for (getFieldError Return to the verification method callback A reminder of )
onErrorClick={
() => {
console.info(getFieldError('account'), 1);
}}
placeholder=" cell-phone number / mailbox / Member name "
>
</InputItem>
</div>
</div>
</div>
)
}
}
// 4. There is another important thing
export default createForm()(Login)
边栏推荐
猜你喜欢
随机推荐
达梦DTS工具使用
koa2 接收不到post方法提交的formData数据(值: {})
ES6常用的新特性
数组常用方法
P7354 "pmoi-1" Knight chess
[dish of learning notes dog learning C] exercise
【学习笔记之菜Dog学C】扫雷游戏
输入一个整数和一棵二元树
P1913 paratroopers in battle
【学习笔记之菜Dog学C】结构体初阶
【学习笔记之菜Dog学C】指针进阶
[dish of learning notes dog learning C] function
Virtual DOM 的实现原理
xshell安装完,启动报错:由于找不到 mfc110.dll,无法继续执行代码。重新安装程序可能会解决此问题
mysql 通过dts迁移至达梦
node 查询目标 目录下所有(文件或文件夹)名为 filename 的文件路径
【学习笔记之菜Dog学C】求值表达式
由两个栈组成的队列
达梦dem部署
虚拟DOM,和实际的DOM有何不同?