fix: form support `disabledOnInputListener` (#5127)
* fix: form support `disabledOnInputListener` * chore: docs updatedev-v5
parent
1d3729aa24
commit
be208fe915
|
@ -14,6 +14,8 @@ setupVbenForm<ComponentType>({
|
||||||
Upload: 'fileList',
|
Upload: 'fileList',
|
||||||
CheckboxGroup: 'model-value',
|
CheckboxGroup: 'model-value',
|
||||||
},
|
},
|
||||||
|
// select等组件的筛选功能会抛出input事件,需要禁用表单的input事件监听以免错误地更新了组件值
|
||||||
|
disabledOnInputListener: true,
|
||||||
},
|
},
|
||||||
defineRules: {
|
defineRules: {
|
||||||
required: (value, _params, ctx) => {
|
required: (value, _params, ctx) => {
|
||||||
|
|
|
@ -139,6 +139,7 @@ const [Form, formApi] = useVbenForm({
|
||||||
fieldName: 'select',
|
fieldName: 'select',
|
||||||
label: 'Select',
|
label: 'Select',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
|
filterable: true,
|
||||||
options: [
|
options: [
|
||||||
{ value: 'A', label: '选项A' },
|
{ value: 'A', label: '选项A' },
|
||||||
{ value: 'B', label: '选项B' },
|
{ value: 'B', label: '选项B' },
|
||||||
|
|
|
@ -44,11 +44,15 @@ export function setupVbenForm<
|
||||||
>(options: VbenFormAdapterOptions<T>) {
|
>(options: VbenFormAdapterOptions<T>) {
|
||||||
const { config, defineRules } = options;
|
const { config, defineRules } = options;
|
||||||
|
|
||||||
const { disabledOnChangeListener = false, emptyStateValue = undefined } =
|
const {
|
||||||
(config || {}) as FormCommonConfig;
|
disabledOnChangeListener = false,
|
||||||
|
disabledOnInputListener = false,
|
||||||
|
emptyStateValue = undefined,
|
||||||
|
} = (config || {}) as FormCommonConfig;
|
||||||
|
|
||||||
Object.assign(DEFAULT_FORM_COMMON_CONFIG, {
|
Object.assign(DEFAULT_FORM_COMMON_CONFIG, {
|
||||||
disabledOnChangeListener,
|
disabledOnChangeListener,
|
||||||
|
disabledOnInputListener,
|
||||||
emptyStateValue,
|
emptyStateValue,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ const {
|
||||||
description,
|
description,
|
||||||
disabled,
|
disabled,
|
||||||
disabledOnChangeListener,
|
disabledOnChangeListener,
|
||||||
|
disabledOnInputListener,
|
||||||
emptyStateValue,
|
emptyStateValue,
|
||||||
fieldName,
|
fieldName,
|
||||||
formFieldProps,
|
formFieldProps,
|
||||||
|
@ -227,10 +228,14 @@ function fieldBindEvent(slotProps: Record<string, any>) {
|
||||||
|
|
||||||
return onChange?.(e?.target?.[bindEventField] ?? e);
|
return onChange?.(e?.target?.[bindEventField] ?? e);
|
||||||
},
|
},
|
||||||
onInput: () => {},
|
...(disabledOnInputListener ? { onInput: undefined } : {}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {};
|
return disabledOnInputListener
|
||||||
|
? {
|
||||||
|
onInput: undefined,
|
||||||
|
}
|
||||||
|
: {};
|
||||||
}
|
}
|
||||||
|
|
||||||
function createComponentProps(slotProps: Record<string, any>) {
|
function createComponentProps(slotProps: Record<string, any>) {
|
||||||
|
|
|
@ -90,6 +90,7 @@ const computedSchema = computed(
|
||||||
controlClass = '',
|
controlClass = '',
|
||||||
disabled,
|
disabled,
|
||||||
disabledOnChangeListener = false,
|
disabledOnChangeListener = false,
|
||||||
|
disabledOnInputListener = false,
|
||||||
emptyStateValue = undefined,
|
emptyStateValue = undefined,
|
||||||
formFieldProps = {},
|
formFieldProps = {},
|
||||||
formItemClass = '',
|
formItemClass = '',
|
||||||
|
@ -111,6 +112,7 @@ const computedSchema = computed(
|
||||||
return {
|
return {
|
||||||
disabled,
|
disabled,
|
||||||
disabledOnChangeListener,
|
disabledOnChangeListener,
|
||||||
|
disabledOnInputListener,
|
||||||
emptyStateValue,
|
emptyStateValue,
|
||||||
hideLabel,
|
hideLabel,
|
||||||
hideRequiredMark,
|
hideRequiredMark,
|
||||||
|
|
|
@ -154,6 +154,11 @@ export interface FormCommonConfig {
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
disabledOnChangeListener?: boolean;
|
disabledOnChangeListener?: boolean;
|
||||||
|
/**
|
||||||
|
* 是否禁用所有表单项的input事件监听
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
disabledOnInputListener?: boolean;
|
||||||
/**
|
/**
|
||||||
* 所有表单项的空状态值,默认都是undefined,naive-ui的空状态值是null
|
* 所有表单项的空状态值,默认都是undefined,naive-ui的空状态值是null
|
||||||
*/
|
*/
|
||||||
|
@ -371,6 +376,7 @@ export interface VbenFormAdapterOptions<
|
||||||
config?: {
|
config?: {
|
||||||
baseModelPropName?: string;
|
baseModelPropName?: string;
|
||||||
disabledOnChangeListener?: boolean;
|
disabledOnChangeListener?: boolean;
|
||||||
|
disabledOnInputListener?: boolean;
|
||||||
emptyStateValue?: null | undefined;
|
emptyStateValue?: null | undefined;
|
||||||
modelPropNameMap?: Partial<Record<T, string>>;
|
modelPropNameMap?: Partial<Record<T, string>>;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue