Skip to content

Injection "Symbol(vee-validate-field-instance)" not found. #4909

@adirizky54

Description

@adirizky54

What happened?

It seems there is an issue when use FieldContextKey

Reproduction steps

I think this error happen when use component from auto import

export default defineNuxtConfig({
  compatibilityDate: '2024-04-03',
  devtools: { enabled: true },
  typescript: {
    typeCheck: true,
    strict: true,
  },
  modules: ['@vee-validate/nuxt'],
  veeValidate: {
    autoImports: true,
    componentNames: {
      Form: 'VeeForm',
      Field: 'VeeField',
      FieldArray: 'VeeFieldArray',
      ErrorMessage: 'VeeErrorMessage',
    },
  },
});
<script setup lang="ts"></script>

<template>
  <form>
    <VeeField v-slot="{ field }" label="Email" name="email">
      <FormItem :id="field.name">
        <input v-bind="field" placeholder="Test" />
      </FormItem>
    </VeeField>

    <button>Submit</button>
  </form>
</template>

Because when i import component from vee-validate directly, it's work

<script setup lang="ts">
import { Field } from 'vee-validate';
</script>

<template>
  <form>
    <Field v-slot="{ field }" label="Email" name="email">
      <FormItem :id="field.name">
        <input v-bind="field" placeholder="Test" />
      </FormItem>
    </Field>

    <button>Submit</button>
  </form>
</template>

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

[Vue warn]: injection "Symbol(vee-validate-field-instance)" not found. 
  at <FormItem id="email" > 
  at <Field label="Email" name="email" > 
  at <App> 
  at <NuxtRoot>

Demo link

https://stackblitz.com/edit/github-dlqgvf?file=composables%2FuseFormField.ts

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions