2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-05-17 02:29:37 +03:00

add required validation doc (#868)

This commit is contained in:
Jeff Sagal
2019-05-03 12:12:43 -07:00
committed by GitHub
parent 8293f2bfd7
commit 7b70b966ff
3 changed files with 76 additions and 0 deletions
@@ -0,0 +1,51 @@
<template>
<form @submit.stop="onSubmit">
<v-select :options="books" label="title" v-model="selected">
<template #search="{attributes, events}">
<input
:required="!selected"
class="vs__search"
v-bind="attributes"
v-on="events"
/>
</template>
</v-select>
<input type="submit">
</form>
</template>
<script>
import books from '../data/books'
export default {
data: () => ({
books,
selected: null,
}),
methods: {
onSubmit() {
alert('Submitted!');
}
}
};
</script>
<style scoped>
form {
display: flex;
align-items: stretch;
}
.v-select {
width: 75%;
}
input[type="submit"] {
margin-left: 1rem;
background: #44ae7d;
border: none;
border-radius: 3px;
color: #fff;
width: 20%;
}
</style>
+1
View File
@@ -117,6 +117,7 @@ module.exports = {
title: 'Digging Deeper',
collapsable: false,
children: [
['guide/validation', 'Validation'],
['guide/vuex', 'Vuex'],
['guide/ajax', 'AJAX'],
],
+24
View File
@@ -0,0 +1,24 @@
## Required
If you need to ensure that a selection is made before a form is submitted, you can
use the `required` attribute in combination with the `search` scoped slot in order
to do so.
However, the `search` input within the component does not actually store a value, so
simply adding the `required` attribute won't work. Instead, we'll bind the attribute
dynamically, so that it's only present if we don't have a selection.
<ValidationRequired />
```html
<v-select :options="books" label="title" v-model="selected">
<template #search="{attributes, events}">
<input
class="vs__search"
:required="!selected"
v-bind="attributes"
v-on="events"
/>
</template>
</v-select>
```