@@ -60,48 +60,75 @@ methods: {
60
60
```
61
61
## Transforming Selections
62
62
63
- When the ` options ` array contains objects, vue-select returns the whole object as dropdown value upon selection.
63
+ When the ` options ` array contains objects, vue-select returns the whole object as dropdown value
64
+ upon selection. This approach makes no assumptions about the data you need, and provides a lot of
65
+ flexibility. However, there will be situations where maybe you just need to return a single key
66
+ from an object.
64
67
65
- If you need to return a single key, or transform the data before it is synced, vue-select provides a ` reduce ` callback
66
- that allows you to transform a selected option before it is passed to the ` @input ` event. Consider this data structure:
68
+ ### Returning a single key with ` reduce `
69
+
70
+ If you need to return a single key, or transform the selection before it is synced, vue-select
71
+ provides a ` reduce ` callback that allows you to transform a selected option before it is passed to
72
+ the ` @input ` event. Consider this data structure:
67
73
68
74
``` js
69
- let options = [{code: ' CA' , country: ' Canada' }, ... ];
75
+ let options = [{code: ' CA' , country: ' Canada' }];
70
76
```
71
77
72
- If we want to display the ` country ` , but return the ` code ` to ` v-model ` , we can use the ` reduce ` prop to receive
73
- only the data that's required.
78
+ If we want to display the ` country ` , but return the ` code ` to ` v-model ` , we can use the ` reduce `
79
+ prop to receive only the data that's required.
74
80
75
81
``` html
76
82
<v-select :options =" options" :reduce =" country => country.code" label =" country" />
77
83
```
84
+
85
+ ### Deep Nested Values
78
86
79
87
The ` reduce ` property also works well when you have a deeply nested value:
80
88
81
89
```
82
90
{
83
91
country: 'canada',
84
92
meta: {
85
- id: '1',
86
93
code: 'ca'
94
+ provinces: [...],
87
95
}
88
96
}
89
97
```
90
98
91
99
``` html
92
- <v-select :options =" options" :reduce =" country => country.value.id " label =" country" />
100
+ <v-select :options =" options" :reduce =" country => country.meta.code " label =" country" />
93
101
```
94
102
95
103
<reducer-nested-value />
96
104
97
105
## Single/Multiple Selection
98
106
99
- By default, vue-select supports choosing a single value. If you need multiple values, use the ` multiple ` boolean prop,
100
- much the same way you would on a native ` <select> ` element. When ` multiple ` is true, ` v-model ` or ` value ` should be
101
- arrays .
107
+ By default, vue-select supports choosing a single value. If you need multiple values, use the
108
+ ` multiple ` boolean prop, much the same way you would on an HTML ` <select> ` element. When ` multiple `
109
+ is true, ` v-model ` and ` value ` must be an array .
102
110
103
111
104
112
``` html
105
- <v-select multiple v-model =" selected" :options =" ['foo','bar']" />
113
+ <v-select multiple v-model =" selected" :options =" ['Canada','United States']" />
114
+ ```
115
+ <v-select multiple :options =" ['Canada','United States'] " />
116
+
117
+ ## Tagging
118
+
119
+ To allow input that's not present within the options, set the ` taggable ` prop to true.
120
+
121
+ ``` html
122
+ <v-select taggable multiple />
106
123
```
107
- <v-select multiple :options =" ['foo','bar'] " />
124
+
125
+ <v-select taggable multiple />
126
+
127
+ If you want added tags to be pushed to the options array, set ` push-tags ` to true.
128
+
129
+ ``` html
130
+ <v-select taggable multiple />
131
+ ```
132
+
133
+ <v-select taggable multiple push-tags />
134
+
0 commit comments