mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-22 10:30:34 +03:00
create selectable docs (#996)
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
<template>
|
||||||
|
<v-select
|
||||||
|
multiple
|
||||||
|
placeholder="Choose up to 3 books!"
|
||||||
|
label="title"
|
||||||
|
v-model="selected"
|
||||||
|
:options="books"
|
||||||
|
:selectable="() => selected.length < 3"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import books from '../data/books';
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return { selected: [] }
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
books: () => books,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<template>
|
||||||
|
<v-select
|
||||||
|
placeholder="Choose a book to read"
|
||||||
|
label="title"
|
||||||
|
:options="books"
|
||||||
|
:selectable="option => ! option.author.lastName.includes('Woodhouse')"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import books from '../data/books';
|
||||||
|
export default {
|
||||||
|
computed: {
|
||||||
|
books: () => books,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -118,6 +118,7 @@ module.exports = {
|
|||||||
collapsable: false,
|
collapsable: false,
|
||||||
children: [
|
children: [
|
||||||
['guide/validation', 'Validation'],
|
['guide/validation', 'Validation'],
|
||||||
|
['guide/selectable', 'Limiting Selections'],
|
||||||
['guide/vuex', 'Vuex'],
|
['guide/vuex', 'Vuex'],
|
||||||
['guide/ajax', 'AJAX'],
|
['guide/ajax', 'AJAX'],
|
||||||
['guide/loops', 'Using in Loops'],
|
['guide/loops', 'Using in Loops'],
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
## Selectable Prop <Badge text="v3.3.0+" />
|
||||||
|
|
||||||
|
The `selectable` prop determines if an option is selectable or not. If `selectable` returns false
|
||||||
|
for a given option, it will be displayed with a `vs__dropdown-option--disabled` class. The option
|
||||||
|
will be disabled and unable to be selected.
|
||||||
|
|
||||||
|
```js
|
||||||
|
selectable: {
|
||||||
|
type: Function,
|
||||||
|
/**
|
||||||
|
* @param {Object|String} option
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
default: option => true,
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
Here `selectable` is used to prevent books by a certain author from being chosen. In this case,
|
||||||
|
the options passed to the component are objects:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
title: "Right Ho Jeeves",
|
||||||
|
author: { firstName: "P.D", lastName: "Woodhouse" },
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This object will be passed to `selectable`, so we can check if the author should be selectable or not.
|
||||||
|
|
||||||
|
<UnselectableExample />
|
||||||
|
|
||||||
|
<<< @/.vuepress/components/UnselectableExample.vue{6}
|
||||||
|
|
||||||
|
## Limiting the Number of Selections
|
||||||
|
|
||||||
|
`selectable` can also be used a bit more creatively to limit the number selections that can be made
|
||||||
|
within the component. In this case, the user can select any author, but may only select a maximum
|
||||||
|
of three books.
|
||||||
|
|
||||||
|
<LimitSelectionQuantity />
|
||||||
|
|
||||||
|
<<< @/.vuepress/components/LimitSelectionQuantity.vue{8}
|
||||||
@@ -229,10 +229,11 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decides wether an option is selectable or not. Not selectable options
|
* Decides whether an option is selectable or not. Not selectable options
|
||||||
* are displayed but disabled and cannot be selected.
|
* are displayed but disabled and cannot be selected.
|
||||||
*
|
*
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
|
* @since 3.3.0
|
||||||
* @param {Object|String} option
|
* @param {Object|String} option
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user