'Vuelidate vue.js latest for vue3 using the helpers.forEach approach for array of objects

Using Vuelidate vue.js latest for vue3 using the helpers.forEach approach for array of objects. I tried running the form but the validation is causing an error given as the below

Gives $response.$errors is undefined in the console Uncaught (in promise) TypeError: $response.$errors is undefined

export default {
  setup () {
    const rules = {
      collection: {
        $each: helpers.forEach({
          name: {
            required
          }
        })
      }
    }
    const state = reactive({
      collection: [
        { name: '' },
      ]
    })
    const v = useVuelidate(rules, state)
    return { v, state }
}
}

This is the template of the code

  <div
    v-for="(input, index) in state.collection"
    :key="index"
    :class="{
        error: v$.collection.$each.$response.$errors[index].name.length,
      }"
  >
    <input v-model="input.name" type="text" />
    <div
      v-for="error in v$.collection.$each.$response.$errors[index].name"
      :key="error"
    >
      {{ error.$message }}
    </div>
  </div>
</template>


Solution 1:[1]

I need to use v$ as this was v$ represented a global variable based on useVuelidate

Solution 2:[2]

Little late, but in your template you are refering to v$.collection instead of v.collection. In your setup you are returning v and not v$

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 iamcoder
Solution 2 moeses