You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -41,7 +41,7 @@ This will make the rules system available throughout your application. The plugi
41
41
Inside of components, you can now import and utilize the rules composable:
42
42
43
43
```js
44
-
import { useRules } from'vuetify/labs/rules'
44
+
import { useRules } from'vuetify'
45
45
46
46
construles=useRules()
47
47
```
@@ -65,7 +65,7 @@ Existing rules' error messages can also be customized on the fly, to fit specifi
65
65
</template>
66
66
67
67
<scriptsetup>
68
-
import { useRules } from'vuetify/labs/rules'
68
+
import { useRules } from'vuetify'
69
69
70
70
construles=useRules()
71
71
@@ -135,10 +135,9 @@ In this case, error message can be redefined as second parameter:
135
135
</v-form>
136
136
```
137
137
138
-
<!--
139
138
## Aliases
140
139
141
-
Rules can also be used in inputs using the alias names syntax:
140
+
Rather than importing `useRules` and calling builders by hand, any rule can be referenced directly in the `rules` prop by its **alias** — a string prefixed with `$` that resolves to the matching builder. This keeps templates terse and lets you skip a component-level `useRules()` call entirely:
142
141
143
142
```html { resource="src/App.vue" }
144
143
<v-form>
@@ -149,29 +148,50 @@ Rules can also be used in inputs using the alias names syntax:
149
148
</v-form>
150
149
```
151
150
152
-
RuleBuilders parameters can also be passed using an Array:
151
+
The example above is shorthand for `[rules.required()]`.
152
+
153
+
::: info
154
+
155
+
Aliases are resolved by the rules plugin, so they only take effect when [`createRulesPlugin`](#installation) is registered. Without it, the string is passed through as-is and treated as a literal error message.
156
+
157
+
:::
158
+
159
+
### Passing options
160
+
161
+
For rules that accept options, use an array where the first item is the alias and the remaining items are the builder's arguments. The last argument can still be a custom error message:
153
162
154
163
```html { resource="src/App.vue" }
155
164
<v-form>
156
165
<v-text-field
157
166
label="Username"
158
167
:rules="[
159
168
['$required', 'This field is mandatory'],
160
-
['$maxLength', 10, 'You can\'t write over 10 characters']
169
+
['$maxLength', 10, 'You can\'t write over 10 characters'],
161
170
]"
162
171
></v-text-field>
163
172
</v-form>
164
173
```
165
-
-->
174
+
175
+
Each array maps to its builder call — `['$maxLength', 10, '…']` resolves to `rules.maxLength(10, '…')`.
176
+
177
+
### Custom aliases
178
+
179
+
Because aliases reference the same builders registered through `createRulesPlugin`, your own [custom rules](#custom-rules) can be used by name too:
180
+
181
+
```html { resource="src/App.vue" }
182
+
<v-text-field
183
+
label="PIN"
184
+
:rules="['$pinCode']"
185
+
></v-text-field>
186
+
```
166
187
167
188
## Custom rules
168
189
169
190
Vuetify comes with an existing set of validation rules but you can overwrite them or add yours.
0 commit comments