Skip to content

Commit 06b2233

Browse files
committed
add getFieldProps
1 parent 1872fcf commit 06b2233

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

mobile-ui/src/components/form/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export interface FormAction {
4949
setFieldsValue: (values: any) => void;
5050
// 设置Field字段
5151
setFields: (fields: FiledData[]) => void;
52+
// 获取Field属性
53+
getFieldProps: (name: NamePath) => FormField | null;
5254
// 校验表单
5355
validate: () => Promise<boolean>;
5456
}
@@ -259,6 +261,15 @@ const Form: React.FC<FormProps> = (props) => {
259261
return form.getFieldsValue();
260262
},
261263

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+
262273
reloadOptions:(name: NamePath) => {
263274
optionContext.notify(name);
264275
},

mobile-ui/src/components/form/validate.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ import {FormAction} from "@/components/form";
44
// 流程表单验证内容
55
export class FormValidateContent {
66
readonly value: any;
7+
readonly name: NamePath;
78
readonly form: FormAction;
89

9-
constructor(value: any, form: FormAction) {
10+
constructor(value: any,name: NamePath, form: FormAction) {
1011
this.value = value;
12+
this.name = name;
1113
this.form = form;
1214
}
15+
16+
getFieldProps = () => {
17+
return this.form.getFieldProps(this.name);
18+
}
1319
}
1420

1521
// 自定义验证上下文
@@ -37,7 +43,7 @@ export class FormValidateContext {
3743
public validateField = (name:NamePath,form: FormAction) => {
3844
return new Promise((resolve,reject)=>{
3945
const value = form.getFieldValue(name);
40-
const content = new FormValidateContent(value, form);
46+
const content = new FormValidateContent(value,name,form);
4147
const validateFunction = this.getValidate(name);
4248
if(validateFunction) {
4349
validateFunction(content)

0 commit comments

Comments
 (0)