File tree 2 files changed +19
-2
lines changed
mobile-ui/src/components/form 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ export interface FormAction {
49
49
setFieldsValue : ( values : any ) => void ;
50
50
// 设置Field字段
51
51
setFields : ( fields : FiledData [ ] ) => void ;
52
+ // 获取Field属性
53
+ getFieldProps : ( name : NamePath ) => FormField | null ;
52
54
// 校验表单
53
55
validate : ( ) => Promise < boolean > ;
54
56
}
@@ -259,6 +261,15 @@ const Form: React.FC<FormProps> = (props) => {
259
261
return form . getFieldsValue ( ) ;
260
262
} ,
261
263
264
+ getFieldProps ( name : NamePath ) : FormField | null {
265
+ for ( const field of fields ) {
266
+ if ( namePathEqual ( field . props . name , name ) ) {
267
+ return field ;
268
+ }
269
+ }
270
+ return null ;
271
+ } ,
272
+
262
273
reloadOptions :( name : NamePath ) => {
263
274
optionContext . notify ( name ) ;
264
275
} ,
Original file line number Diff line number Diff line change @@ -4,12 +4,18 @@ import {FormAction} from "@/components/form";
4
4
// 流程表单验证内容
5
5
export class FormValidateContent {
6
6
readonly value : any ;
7
+ readonly name : NamePath ;
7
8
readonly form : FormAction ;
8
9
9
- constructor ( value : any , form : FormAction ) {
10
+ constructor ( value : any , name : NamePath , form : FormAction ) {
10
11
this . value = value ;
12
+ this . name = name ;
11
13
this . form = form ;
12
14
}
15
+
16
+ getFieldProps = ( ) => {
17
+ return this . form . getFieldProps ( this . name ) ;
18
+ }
13
19
}
14
20
15
21
// 自定义验证上下文
@@ -37,7 +43,7 @@ export class FormValidateContext {
37
43
public validateField = ( name :NamePath , form : FormAction ) => {
38
44
return new Promise ( ( resolve , reject ) => {
39
45
const value = form . getFieldValue ( name ) ;
40
- const content = new FormValidateContent ( value , form ) ;
46
+ const content = new FormValidateContent ( value , name , form ) ;
41
47
const validateFunction = this . getValidate ( name ) ;
42
48
if ( validateFunction ) {
43
49
validateFunction ( content )
You can’t perform that action at this time.
0 commit comments