vuetify icon indicating copy to clipboard operation
vuetify copied to clipboard

[Bug Report][3.8.8] useRules composable broken

Open laventnc opened this issue 8 months ago • 2 comments

Environment

Vuetify Version: 3.8.8 Last working version: 3.8.5 Vue Version: 3.5.16 Browsers: Chrome 137.0.0.0 OS: Windows 10

Steps to reproduce

useRules() composable now accepts a function, and this isn't mentioned in the documentation

Expected Behavior

useRules() to still work as documented or documentation is updated

Actual Behavior

doesn't work

Reproduction Link

https://play.vuetifyjs.com/#...

laventnc avatar Jun 10 '25 21:06 laventnc

link to PR that seems to have caused it

laventnc avatar Jun 11 '25 13:06 laventnc

I don't have a reproducible link, but after digging through the code a bit I realized this is more a change in functionality than a bug. Basically, rules are meant to be used through the component's rules prop, instead of directly through the useRules composable.

Instead of the documented method:

<script setup lang="ts">
const rules = useRules()
</script>

<template>
  <v-text-field
    :rules="[rules.required]"
  />
</template>

You now can simply pass the name of the rule:

<template>
  <v-text-field
    :rules="['required']"
  />
</template>

Note that this does work with custom rules as well! Let me know if I should update the issue report to be more specific about the documentation being wrong as it appears this was intended.

Edit: And for rules that require arguments, looks like you can pass an array:

<template>
  <v-text-field
    :rules="[
      'required',
      ['patttern', /^[\w\s\.-]+$/, 'Invalid name.']
    ]"
  />
</template>

laventnc avatar Jun 11 '25 13:06 laventnc

Seems to be a duplicate of https://github.com/vuetifyjs/vuetify/issues/21477

saufdermaur avatar Jun 21 '25 08:06 saufdermaur