diff --git a/packages/components/form/src/form-item.vue b/packages/components/form/src/form-item.vue index 616d8d7e7f..ae8b6a5d84 100644 --- a/packages/components/form/src/form-item.vue +++ b/packages/components/form/src/form-item.vue @@ -379,6 +379,7 @@ const context: FormItemContext = reactive({ inputIds, isGroup, hasLabel, + fieldValue, addInputId, removeInputId, resetField, diff --git a/packages/components/form/src/form.vue b/packages/components/form/src/form.vue index 415df285a1..495bff7d63 100644 --- a/packages/components/form/src/form.vue +++ b/packages/components/form/src/form.vue @@ -48,6 +48,10 @@ const formClasses = computed(() => { ] }) +const getField: FormContext['getField'] = (prop) => { + return fields.find((field) => field.prop === prop) +} + const addField: FormContext['addField'] = (field) => { fields.push(field) } @@ -168,6 +172,7 @@ provide( resetFields, clearValidate, validateField, + getField, addField, removeField, diff --git a/packages/components/form/src/types.ts b/packages/components/form/src/types.ts index 8a33834526..f1180f787d 100644 --- a/packages/components/form/src/types.ts +++ b/packages/components/form/src/types.ts @@ -113,8 +113,7 @@ export interface FormValidateFailure { export type FormContext = FormProps & UnwrapRef & { emit: SetupContext['emit'] - - // expose + getField: (prop: string) => FormItemContext | undefined addField: (field: FormItemContext) => void removeField: (field: FormItemContext) => void resetFields: (props?: Arrayable) => void @@ -133,6 +132,7 @@ export interface FormItemContext extends FormItemProps { labelId: string inputIds: string[] hasLabel: boolean + fieldValue: any addInputId: (id: string) => void removeInputId: (id: string) => void validate: (