feat(components): [form] FormContext adds the getField method (#14930)

* feat(components): [form] FormContext adds the getField method

* feat(components): [form-item] FormItemContext adds the fieldValue prop

* chore: update FormContext.getField return type
This commit is contained in:
云淡然 2023-12-31 08:39:31 +08:00 committed by GitHub
parent ff7f80d941
commit 736dfa631f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View File

@ -379,6 +379,7 @@ const context: FormItemContext = reactive({
inputIds,
isGroup,
hasLabel,
fieldValue,
addInputId,
removeInputId,
resetField,

View File

@ -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,

View File

@ -113,8 +113,7 @@ export interface FormValidateFailure {
export type FormContext = FormProps &
UnwrapRef<FormLabelWidthContext> & {
emit: SetupContext<FormEmits>['emit']
// expose
getField: (prop: string) => FormItemContext | undefined
addField: (field: FormItemContext) => void
removeField: (field: FormItemContext) => void
resetFields: (props?: Arrayable<FormItemProp>) => 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: (