Skip to content

Commit

Permalink
fix: handleBlur should respect blur validate config closes #4285
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed May 31, 2023
1 parent fb9a0da commit 6e074f7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/popular-fans-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vee-validate': patch
---

fix: handleBlur should respect blur validate config closes #4285
2 changes: 1 addition & 1 deletion packages/vee-validate/src/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const FieldImpl = /** #__PURE__ */ defineComponent({
handleChange: onChangeHandler,
handleInput: e => onChangeHandler(e, false),
handleReset,
handleBlur,
handleBlur: sharedProps.value.onBlur,
setTouched,
setErrors,
};
Expand Down
19 changes: 19 additions & 0 deletions packages/vee-validate/tests/Field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1241,4 +1241,23 @@ describe('<Field />', () => {
expect(valuesEl?.textContent).toBe('123');
});
});

// #4285
test('handle blur should respect the validate on blur config', async () => {
mountWithHoc({
template: `
<Field name="field" rules="required" v-slot="{ errorMessage, handleBlur }" validateOnBlur>
<input @blur="handleBlur" />
<span>{{ errorMessage }}</span>
</Field>
`,
});

await flushPromises();
const input = document.querySelector('input') as HTMLInputElement;
const error = document.querySelector('span') as HTMLInputElement;
dispatchEvent(input, 'blur');
await flushPromises();
expect(error.textContent).toBe(REQUIRED_MESSAGE);
});
});

0 comments on commit 6e074f7

Please sign in to comment.