antDeaign-form-getFieldDecorator 使用注意事項


2020-01-06

antDeaign-form-getFieldDecorator 使用注意事項

一、使用getFieldDecorator之前,必須先使用 Form.create(})(Form) 將表單組件包裹起來

class ControlForm extends React.Component {} // 導出時將組件 ControlForm 用 Form.create()包裹起來
export default Form.create()(ControlForm)

 

二、經過 Form.create 包裝的組件將會自帶 this.props.form 屬性,通過解構賦值將 form 解構出來

// 解構出 form
const {form} = this.props
// 解構出 getFieldDecorator const {getFieldDecorator} = form

 

三、使用 getFieldDecorator 方法

 

<Form.Item label={item.label}> { getFieldDecorator(item.label, { // 默認值(初始值)
     initialValue: 5, // 校驗規則:最大長度、最小長度、校驗文案、正則表達式校驗、是否必選
 rules: [ { min: 3, max: 5, message: '長度應在3~5個字符', }, { required: true, }, { pattern: '^[a-zA-Z]\w{5,17}$', message: '以字母開頭,長度在6~18之間,只能包含字母、數字和下划線)', }, ], })(<Input />)}
</Form.Item>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM