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
Use the `inputAttrs` prop to add HTML attributes to the search input element. This is particularly useful for form integration, accessibility, and browser features.
8
+
9
+
## Autocomplete Support
10
+
11
+
Enable browser autocomplete by setting the `autocomplete` attribute:
12
+
13
+
```vue
14
+
<template>
15
+
<VueSelect
16
+
v-model="selectedCountry"
17
+
:options="countries"
18
+
:input-attrs="{ autocomplete: 'country' }"
19
+
placeholder="Select your country"
20
+
/>
21
+
22
+
<VueSelect
23
+
v-model="selectedUsername"
24
+
:options="usernames"
25
+
:input-attrs="{ autocomplete: 'username' }"
26
+
placeholder="Select username"
27
+
is-taggable
28
+
/>
29
+
</template>
30
+
```
31
+
32
+
::: warning
33
+
`autocomplete` browser UI might conflict with the component's UI. For example, if you are using the `autocomplete` attribute on a select field, the browser will show a dropdown of autocomplete options. To avoid this, you can set the `autocomplete` attribute to `off` (which is the default value).
34
+
:::
35
+
36
+
## Required Field Validation
37
+
38
+
Mark fields as required for HTML5 form validation:
39
+
40
+
```vue
41
+
<template>
42
+
<form @submit.prevent="handleSubmit">
43
+
<VueSelect
44
+
v-model="selectedCountry"
45
+
:options="countries"
46
+
:input-attrs="{ required: true }"
47
+
placeholder="Country (required)"
48
+
/>
49
+
50
+
<button type="submit">
51
+
Submit
52
+
</button>
53
+
</form>
54
+
</template>
55
+
```
56
+
57
+
::: info
58
+
It isn't recommended to use HTML5 form validation with custom components, as you might run into issues. It's better instead to use a dedicated library for form validation (e.g. vee-validate) as it's easier to connect it with the component's data.
59
+
:::
60
+
61
+
## Data Attributes
62
+
63
+
Add custom data attributes for testing or analytics:
64
+
65
+
```vue
66
+
<template>
67
+
<VueSelect
68
+
v-model="selectedOption"
69
+
:options="options"
70
+
:input-attrs="{
71
+
'data-testid': 'user-preference-select',
72
+
'data-analytics': 'form-interaction',
73
+
'data-component': 'country-selector',
74
+
}"
75
+
/>
76
+
</template>
77
+
```
78
+
79
+
## Overriding Default Attributes
80
+
81
+
The component sets some default attributes that you can override:
82
+
83
+
-`autocapitalize: "none"`
84
+
-`autocomplete: "off"`
85
+
-`autocorrect: "off"`
86
+
-`spellcheck: false`
87
+
-`tabindex: 0`
88
+
-`type: "text"`
89
+
90
+
Essential attributes like `aria-autocomplete`, `aria-labelledby`, `disabled`, and `placeholder` are preserved and cannot be overridden through `inputAttrs`.
0 commit comments