victorgarciaesgi / regle

📏 Typescript first model-based form validation library for Vue 3
https://regle.vercel.app
MIT License
11 stars 1 forks source link

Validation breaks with collection rules #22

Open martinhla opened 16 hours ago

martinhla commented 16 hours ago

Hi, I'm encountering an error while validating collections with the following configuration:

const { r$ } = useRegle(data, {
  name: { required },
  levels: {
    minLength: minLength(1),
    maxLength: maxLength(3),
    $each: () => ({
      name: { required },
      localizations: {
        $each: () => ({
          name: { required },
        }),
      },
    }),
  },
});

When I attempt to add a level: { name: 'a', localizations: [{ name: 'a' }] }, I receive the following error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '0')

Reproduction: https://stackblitz.com/edit/vitejs-vite-wa6v5z?file=src%2FApp.vue just click on add level button and you will see the error

victorgarciaesgi commented 13 hours ago

Thanks for the report! I must have missed something with nested collections callbacks. I'll take a look

victorgarciaesgi commented 13 hours ago

Luckily just a mistake on my part on an undefined check, easy fix. Will be pushed in the next update 👍

martinhla commented 1 hour ago

thanks for fix. i will try that after update 👍