Skip to content

Commit 9418cbf

Browse files
committed
fix: form support disabledOnInputListener
1 parent 1d3729a commit 9418cbf

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

apps/web-ele/src/adapter/form.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ setupVbenForm<ComponentType>({
1414
Upload: 'fileList',
1515
CheckboxGroup: 'model-value',
1616
},
17+
// select等组件的筛选功能会抛出input事件,需要禁用表单的input事件监听以免错误地更新了组件值
18+
disabledOnInputListener: true,
1719
},
1820
defineRules: {
1921
required: (value, _params, ctx) => {

apps/web-ele/src/views/demos/form/basic.vue

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const [Form, formApi] = useVbenForm({
139139
fieldName: 'select',
140140
label: 'Select',
141141
componentProps: {
142+
filterable: true,
142143
options: [
143144
{ value: 'A', label: '选项A' },
144145
{ value: 'B', label: '选项B' },

packages/@core/ui-kit/form-ui/src/config.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ export function setupVbenForm<
4444
>(options: VbenFormAdapterOptions<T>) {
4545
const { config, defineRules } = options;
4646

47-
const { disabledOnChangeListener = false, emptyStateValue = undefined } =
48-
(config || {}) as FormCommonConfig;
47+
const {
48+
disabledOnChangeListener = false,
49+
disabledOnInputListener = false,
50+
emptyStateValue = undefined,
51+
} = (config || {}) as FormCommonConfig;
4952

5053
Object.assign(DEFAULT_FORM_COMMON_CONFIG, {
5154
disabledOnChangeListener,
55+
disabledOnInputListener,
5256
emptyStateValue,
5357
});
5458

packages/@core/ui-kit/form-ui/src/form-render/form-field.vue

+7-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const {
3333
description,
3434
disabled,
3535
disabledOnChangeListener,
36+
disabledOnInputListener,
3637
emptyStateValue,
3738
fieldName,
3839
formFieldProps,
@@ -227,10 +228,14 @@ function fieldBindEvent(slotProps: Record<string, any>) {
227228
228229
return onChange?.(e?.target?.[bindEventField] ?? e);
229230
},
230-
onInput: () => {},
231+
...(disabledOnInputListener ? { onInput: undefined } : {}),
231232
};
232233
}
233-
return {};
234+
return disabledOnInputListener
235+
? {
236+
onInput: undefined,
237+
}
238+
: {};
234239
}
235240
236241
function createComponentProps(slotProps: Record<string, any>) {

packages/@core/ui-kit/form-ui/src/form-render/form.vue

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const computedSchema = computed(
9090
controlClass = '',
9191
disabled,
9292
disabledOnChangeListener = false,
93+
disabledOnInputListener = false,
9394
emptyStateValue = undefined,
9495
formFieldProps = {},
9596
formItemClass = '',
@@ -111,6 +112,7 @@ const computedSchema = computed(
111112
return {
112113
disabled,
113114
disabledOnChangeListener,
115+
disabledOnInputListener,
114116
emptyStateValue,
115117
hideLabel,
116118
hideRequiredMark,

packages/@core/ui-kit/form-ui/src/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ export interface FormCommonConfig {
154154
* @default false
155155
*/
156156
disabledOnChangeListener?: boolean;
157+
/**
158+
* 是否禁用所有表单项的input事件监听
159+
* @default true
160+
*/
161+
disabledOnInputListener?: boolean;
157162
/**
158163
* 所有表单项的空状态值,默认都是undefined,naive-ui的空状态值是null
159164
*/
@@ -371,6 +376,7 @@ export interface VbenFormAdapterOptions<
371376
config?: {
372377
baseModelPropName?: string;
373378
disabledOnChangeListener?: boolean;
379+
disabledOnInputListener?: boolean;
374380
emptyStateValue?: null | undefined;
375381
modelPropNameMap?: Partial<Record<T, string>>;
376382
};

0 commit comments

Comments
 (0)