mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-11-30 02:08:12 +08:00
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:
parent
ff7f80d941
commit
736dfa631f
@ -379,6 +379,7 @@ const context: FormItemContext = reactive({
|
||||
inputIds,
|
||||
isGroup,
|
||||
hasLabel,
|
||||
fieldValue,
|
||||
addInputId,
|
||||
removeInputId,
|
||||
resetField,
|
||||
|
@ -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,
|
||||
|
||||
|
@ -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: (
|
||||
|
Loading…
Reference in New Issue
Block a user