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 doesnt work in options API #1236

Open
xspaniki opened this issue Apr 3, 2024 · 0 comments
Open

useVuelidate doesnt work in options API #1236

xspaniki opened this issue Apr 3, 2024 · 0 comments

Comments

@xspaniki
Copy link

xspaniki commented Apr 3, 2024

I wanted to migrate vuelidate 0.x to 2.x and use options API syntax from example

import { useVuelidate } from '@vuelidate/core'

export default {
  name: 'UsersPage',
  data: () => ({
    form: {
      name: '',
      email: ''
    }
  }),
  setup: () => ({ v$: useVuelidate() }),
  validations () {
    return {
      form: {
        name: { required },
        email: { required, email }
      }
    }
  }
}

rendered object in dom:
Screenshot 2024-04-03 at 15 23 33

but for some reason useVuelidate doesnt use data and validations, v$ object doesnt contains validations. When i tried composition API example it works

import { reactive } from 'vue' // or '@vue/composition-api' in Vue 2.x
import { useVuelidate } from '@vuelidate/core'
import { email, required } from '@vuelidate/validators'

export default {
  setup () {
    const state = reactive({
      name: '',
      emailAddress: ''
    })
    const rules = {
      name: { required },
      emailAddress: { required, email }
    }

    const v$ = useVuelidate(rules, state)

    return { state, v$ }
  }
}

rendered object in dom:
Screenshot 2024-04-03 at 15 21 04

versions:
vue@2.7.16
@vuelidate/core@2.0.3
@vuelidate/validators@2.0.4

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

1 participant