Skip to content

Commit 5215edd

Browse files
authored
add guide for reduce and taggable (sagalbot#827)
1 parent b34bf57 commit 5215edd

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

docs/guide/values.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,45 @@ If you want added tags to be pushed to the options array, set `push-tags` to tru
132132

133133
<v-select taggable multiple push-tags />
134134

135+
### Using `taggable` & `reduce` together
136+
137+
When combining `taggable` with `reduce`, you must define the `createOption` prop. The
138+
`createOption` function is responsible for defining the structure of the objects that Vue Select
139+
will create for you when adding a tag. It should return a value that has the same properties as the
140+
rest of your `options`.
141+
142+
If you don't define `createOption`, Vue Select will construct a simple object following this structure:
143+
`{[this.label]: searchText}`. If you're using `reduce`, this is probably not what your options look
144+
like, which is why you'll need to set the function yourself.
145+
146+
**Example**
147+
148+
We have a taggable select for adding books to a collection. We're just concerned about getting the
149+
book title added, and our server side code will add the author details in a background process. The
150+
user has already selected a book.
151+
152+
```js
153+
const options = [
154+
{
155+
title: "HTML5",
156+
author: {
157+
firstName: "Remy",
158+
lastName: "Sharp"
159+
}
160+
}
161+
];
162+
```
163+
164+
```html
165+
<v-select
166+
taggable
167+
multiple
168+
label="title"
169+
:options="options"
170+
:create-option="book => ({ title: book, author: { firstName: '', lastName: '' } })"
171+
:reduce="book => `${book.author.firstName} ${book.author.lastName}`"
172+
/>
173+
```
174+
175+
176+

0 commit comments

Comments
 (0)