diff --git a/src/field/Field.tsx b/src/field/Field.tsx index 77742cf70..3fcf4a4bf 100644 --- a/src/field/Field.tsx +++ b/src/field/Field.tsx @@ -238,7 +238,9 @@ export default defineComponent({ return defaultTrigger; }); - validate(rules); + if (rules.length) { + validate(rules); + } } }; diff --git a/src/form/test/index.spec.tsx b/src/form/test/index.spec.tsx new file mode 100644 index 000000000..c5d09d9be --- /dev/null +++ b/src/form/test/index.spec.tsx @@ -0,0 +1,36 @@ +import { Form } from '..'; +import { Field } from '../../field'; +import { mountForm } from './shared'; +import { later } from '../../../test'; + +test('should not reset validation after blured when validate-trigger is onChange', async () => { + const validator = (val: string) => val.length > 4; + const wrapper = mountForm({ + data() { + return { + value: '', + }; + }, + render() { + return ( +
+ + + ); + }, + }); + + const input = wrapper.find('input'); + input.element.value = '1'; + await input.trigger('input'); + await later(); + + expect(wrapper.find('.van-field__error-message').exists()).toBeTruthy(); + + await input.trigger('blur'); + expect(wrapper.find('.van-field__error-message').exists()).toBeTruthy(); +});