fix: form support disabledOnInputListener (#5127)

* fix: form support `disabledOnInputListener`

* chore: docs update
This commit is contained in:
Netfan
2024-12-13 11:18:45 +08:00
committed by GitHub
parent 1d3729aa24
commit be208fe915
6 changed files with 24 additions and 4 deletions

View File

@@ -44,11 +44,15 @@ export function setupVbenForm<
>(options: VbenFormAdapterOptions<T>) {
const { config, defineRules } = options;
const { disabledOnChangeListener = false, emptyStateValue = undefined } =
(config || {}) as FormCommonConfig;
const {
disabledOnChangeListener = false,
disabledOnInputListener = false,
emptyStateValue = undefined,
} = (config || {}) as FormCommonConfig;
Object.assign(DEFAULT_FORM_COMMON_CONFIG, {
disabledOnChangeListener,
disabledOnInputListener,
emptyStateValue,
});

View File

@@ -33,6 +33,7 @@ const {
description,
disabled,
disabledOnChangeListener,
disabledOnInputListener,
emptyStateValue,
fieldName,
formFieldProps,
@@ -227,10 +228,14 @@ function fieldBindEvent(slotProps: Record<string, any>) {
return onChange?.(e?.target?.[bindEventField] ?? e);
},
onInput: () => {},
...(disabledOnInputListener ? { onInput: undefined } : {}),
};
}
return {};
return disabledOnInputListener
? {
onInput: undefined,
}
: {};
}
function createComponentProps(slotProps: Record<string, any>) {

View File

@@ -90,6 +90,7 @@ const computedSchema = computed(
controlClass = '',
disabled,
disabledOnChangeListener = false,
disabledOnInputListener = false,
emptyStateValue = undefined,
formFieldProps = {},
formItemClass = '',
@@ -111,6 +112,7 @@ const computedSchema = computed(
return {
disabled,
disabledOnChangeListener,
disabledOnInputListener,
emptyStateValue,
hideLabel,
hideRequiredMark,

View File

@@ -154,6 +154,11 @@ export interface FormCommonConfig {
* @default false
*/
disabledOnChangeListener?: boolean;
/**
* 是否禁用所有表单项的input事件监听
* @default false
*/
disabledOnInputListener?: boolean;
/**
* 所有表单项的空状态值,默认都是undefinednaive-ui的空状态值是null
*/
@@ -371,6 +376,7 @@ export interface VbenFormAdapterOptions<
config?: {
baseModelPropName?: string;
disabledOnChangeListener?: boolean;
disabledOnInputListener?: boolean;
emptyStateValue?: null | undefined;
modelPropNameMap?: Partial<Record<T, string>>;
};