Skip to content

Commit ce2f539

Browse files
committed
fix(types): textarea field binding error closes #4031
1 parent 18f3c1c commit ce2f539

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

packages/vee-validate/src/Field.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { normalizeChildren, hasCheckedAttr, shouldHaveValueBinding, isPropPresen
55
import { IS_ABSENT } from './symbols';
66
import { FieldMeta, InputType } from './types';
77
import { FieldContext } from '.';
8+
import { isCallable } from '../../shared';
89

910
interface ValidationTriggersProps {
1011
validateOnMount: boolean;
@@ -14,15 +15,13 @@ interface ValidationTriggersProps {
1415
validateOnModelUpdate: boolean;
1516
}
1617

17-
type EventHandlerBinding<T> = T | T[];
18-
19-
interface FieldBindingObject<TValue = unknown> {
18+
interface FieldBindingObject<TValue = any> {
2019
name: string;
21-
onBlur: EventHandlerBinding<(e: Event) => unknown>;
22-
onInput: EventHandlerBinding<(e: Event) => unknown>;
23-
onChange: EventHandlerBinding<(e: Event) => unknown>;
20+
onBlur: (e: Event) => void;
21+
onInput: (e: Event) => void;
22+
onChange: (e: Event) => void;
2423
'onUpdate:modelValue'?: ((e: TValue) => unknown) | undefined;
25-
value?: unknown;
24+
value?: TValue;
2625
checked?: boolean;
2726
}
2827

@@ -162,13 +161,31 @@ const FieldImpl = defineComponent({
162161
const fieldProps = computed(() => {
163162
const { validateOnInput, validateOnChange, validateOnBlur, validateOnModelUpdate } =
164163
resolveValidationTriggers(props);
165-
const baseOnBlur: any = [handleBlur, ctx.attrs.onBlur, validateOnBlur ? validateField : undefined].filter(
166-
Boolean
167-
);
168-
const baseOnInput: any = [(e: unknown) => onChangeHandler(e, validateOnInput), ctx.attrs.onInput].filter(Boolean);
169-
const baseOnChange: any = [(e: unknown) => onChangeHandler(e, validateOnChange), ctx.attrs.onChange].filter(
170-
Boolean
171-
);
164+
165+
function baseOnBlur(e: Event) {
166+
handleBlur(e);
167+
if (isCallable(ctx.attrs.onBlur)) {
168+
ctx.attrs.onBlur(e);
169+
}
170+
171+
if (validateOnBlur) {
172+
validateField();
173+
}
174+
}
175+
176+
function baseOnInput(e: Event) {
177+
onChangeHandler(e, validateOnInput);
178+
if (isCallable(ctx.attrs.onInput)) {
179+
ctx.attrs.onInput(e);
180+
}
181+
}
182+
183+
function baseOnChange(e: Event) {
184+
onChangeHandler(e, validateOnChange);
185+
if (isCallable(ctx.attrs.onChange)) {
186+
ctx.attrs.onChange(e);
187+
}
188+
}
172189

173190
const attrs: FieldBindingObject<unknown> = {
174191
name: props.name,

0 commit comments

Comments
 (0)