Skip to content

Commit

Permalink
refactor: use expose API instead of the hacky render hook
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Jul 29, 2021
1 parent c465dc6 commit b662c3d
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions packages/vee-validate/src/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,20 @@ export const Form = defineComponent({
};
}

return function renderForm(this: any) {
// FIXME: Hacky but cute way to expose some stuff to the rendered instance
// getCurrentInstance doesn't work with render fns, it returns the wrong instance
// we want to expose setFieldError and setErrors
if (!('setErrors' in this)) {
this.setFieldError = setFieldError;
this.setErrors = setErrors;
this.setFieldValue = setFieldValue;
this.setValues = setValues;
this.setFieldTouched = setFieldTouched;
this.setTouched = setTouched;
this.resetForm = resetForm;
this.validate = validate;
this.validateField = validateField;
}
// expose these functions and methods as part of public API
ctx.expose({
setFieldError,
setErrors,
setFieldValue,
setValues,
setFieldTouched,
setTouched,
resetForm,
validate,
validateField,
});

return function renderForm() {
// avoid resolving the form component as itself
const tag = props.as === 'form' ? props.as : (resolveDynamicComponent(props.as) as string);
const children = normalizeChildren(tag, ctx, slotProps);
Expand Down

0 comments on commit b662c3d

Please sign in to comment.