Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useVuelidate doesn't signal that it unwraps the validation ref when used in a template #1217

Open
GalacticHypernova opened this issue Dec 10, 2023 · 2 comments

Comments

@GalacticHypernova
Copy link

GalacticHypernova commented Dec 10, 2023

Make sure that you are familiar with documentation before submitting an issue.

https://vuelidate-next.netlify.com/

Describe the bug
When attempting to access a property in a vuelidate validation "form" in the template (like in a v-if), the validation ref doesn't get unwrapped according to TS.

Reproduction URL
image

If need be, I'll share my project privately, as I have many things on there that I don't think are needed to be revealed to everyone.

To Reproduce
Steps to reproduce the behavior:

  1. Create a validation with useVuelidate (we'll call it v$ for the example), like:
<script setup lang="ts">
import { useVuelidate } from "@vuelidate/core"
import { required,} from "@vuelidate/validators"

const form=reactive({name:""})
const v$ = useVuelidate({name:{required}},form})
</script>
  1. Add a <p v-if="v$.name"> element
  2. Profit

Expected behavior
The validation ref should get detected as unwrapped within the template

Screenshots
Provided above

Additional context
It doesn't actually break anything, however it is a bit annoying to work with.

@GalacticHypernova GalacticHypernova changed the title useVuelidate doesn't signal that it unwrap the validation ref when used in a template useVuelidate doesn't signal that it unwraps the validation ref when used in a template Dec 10, 2023
@VividLemon
Copy link

Add a <p v-if="v$.name> element

This doesn't have an issue. So, I'm confused about what this is exactly referring to.

However, what does error is the issue of

export interface ErrorObject {
  readonly $propertyPath: string
  readonly $property: string
  readonly $validator: string
  readonly $message: string | Ref<string>
  readonly $params: object
  readonly $pending: boolean
  readonly $response: any,
  readonly $uid: string,
}

readonly $message: string | Ref<string>

The issue with doing something like v$.name.$errors.map((el) => el.$message) is problematic. the nested Ref of $message is not going to be unwrapped -- either through template, another ref, or reactive (https://vuejs.org/guide/essentials/reactivity-fundamentals.html#caveat-in-arrays-and-collections) This leads to the issue with the Vuetify mentioned issue.

My best advice in this case would be to remove the Ref from that type and ensure that the $errors object is either a ref or reactive already -- no use in wrapping it (I'm pretty sure!)

This particular issue I'm noting is not directly related to the original issue. But its a large issue for Vuetify apps! I am fully willing to make any modifications to the lib, but I need to know if its okay, considering it could be a breaking-change bug

@GalacticHypernova
Copy link
Author

GalacticHypernova commented Jan 25, 2024

My best advice in this case would be to remove the Ref from that type

The issue is trying to access any property results in that error, which is just not great for DX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants