fix(@vben-core/form-ui): correct field slot props (#8216)
This commit is contained in:
@@ -264,7 +264,7 @@ watch(
|
||||
);
|
||||
|
||||
const shouldDisabled = computed(() => {
|
||||
return isDisabled.value || disabled || computedProps.value?.disabled;
|
||||
return Boolean(isDisabled.value || disabled || computedProps.value?.disabled);
|
||||
});
|
||||
|
||||
const customContentRender = computed(() => {
|
||||
@@ -307,14 +307,20 @@ function createFieldSlotProps(slotProps: RuntimeFieldSlotProps) {
|
||||
};
|
||||
}
|
||||
|
||||
function fieldBindEvent(componentField: Record<string, any>) {
|
||||
function resolveModelPropName() {
|
||||
return (
|
||||
modelPropName ||
|
||||
(isString(component) ? componentBindEventMap.value?.[component] : null)
|
||||
);
|
||||
}
|
||||
|
||||
function fieldBindEvent(
|
||||
componentField: Record<string, any>,
|
||||
bindEventField: null | string | undefined,
|
||||
) {
|
||||
const modelValue = componentField.modelValue;
|
||||
const handler = componentField['onUpdate:modelValue'];
|
||||
|
||||
const bindEventField =
|
||||
modelPropName ||
|
||||
(isString(component) ? componentBindEventMap.value?.[component] : null);
|
||||
|
||||
let value = modelValue;
|
||||
// antd design 的一些组件会传递一个 event 对象
|
||||
if (modelValue && isObject(modelValue) && bindEventField) {
|
||||
@@ -348,7 +354,11 @@ function fieldBindEvent(componentField: Record<string, any>) {
|
||||
|
||||
function createComponentProps(slotProps: RuntimeFieldSlotProps) {
|
||||
const normalizedSlotProps = createFieldSlotProps(slotProps);
|
||||
const bindEvents = fieldBindEvent(normalizedSlotProps.componentField);
|
||||
const bindEventField = resolveModelPropName();
|
||||
const bindEvents = fieldBindEvent(
|
||||
normalizedSlotProps.componentField,
|
||||
bindEventField,
|
||||
);
|
||||
|
||||
const binds = {
|
||||
...normalizedSlotProps.componentField,
|
||||
@@ -361,6 +371,10 @@ function createComponentProps(slotProps: RuntimeFieldSlotProps) {
|
||||
? { onInput: computedProps.value.onInput }
|
||||
: {}),
|
||||
};
|
||||
if (bindEventField && bindEventField !== 'modelValue') {
|
||||
Reflect.deleteProperty(binds, 'modelValue');
|
||||
Reflect.deleteProperty(binds, 'onUpdate:modelValue');
|
||||
}
|
||||
|
||||
return binds;
|
||||
}
|
||||
|
||||
@@ -235,16 +235,19 @@ export interface VbenFormDefaultSlotProps<
|
||||
|
||||
export interface VbenFormFieldSlotProps<
|
||||
TValues extends FormValues = FormValues,
|
||||
TFieldName extends KnownFormFieldName<TValues> = KnownFormFieldName<TValues>,
|
||||
TFieldName extends FormFieldName<TValues> = FormFieldName<TValues>,
|
||||
T extends BaseFormComponentType = BaseFormComponentType,
|
||||
P extends Record<string, any> = Record<never, never>,
|
||||
TSubmitValues extends FormValues = TValues,
|
||||
> extends VbenFormActionSlotProps<TValues, T, P, TSubmitValues> {
|
||||
componentField: FormComponentField<TValues[TFieldName], TFieldName>;
|
||||
componentField: FormComponentField<
|
||||
FormFieldValue<TValues, TFieldName>,
|
||||
TFieldName
|
||||
>;
|
||||
disabled: boolean;
|
||||
field: FormRuntimeField<TValues[TFieldName]>;
|
||||
field: FormRuntimeField<FormFieldValue<TValues, TFieldName>>;
|
||||
isInValid: boolean;
|
||||
modelValue: TValues[TFieldName];
|
||||
modelValue: FormFieldValue<TValues, TFieldName>;
|
||||
name: TFieldName;
|
||||
}
|
||||
|
||||
@@ -255,7 +258,19 @@ type VbenFormFieldSlots<
|
||||
TSubmitValues extends FormValues,
|
||||
> =
|
||||
string extends Extract<keyof TValues, string>
|
||||
? Record<string, ((props: any) => any) | undefined>
|
||||
? Record<
|
||||
string,
|
||||
| ((
|
||||
props: VbenFormFieldSlotProps<
|
||||
TValues,
|
||||
FormFieldName<TValues>,
|
||||
T,
|
||||
P,
|
||||
TSubmitValues
|
||||
>,
|
||||
) => any)
|
||||
| undefined
|
||||
>
|
||||
: {
|
||||
[TFieldName in KnownFormFieldName<TValues>]?: (
|
||||
props: VbenFormFieldSlotProps<
|
||||
|
||||
Reference in New Issue
Block a user