File tree Expand file tree Collapse file tree 3 files changed +76
-0
lines changed Expand file tree Collapse file tree 3 files changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+ <template >
2
+ <form @submit.stop =" onSubmit" >
3
+ <v-select :options =" books" label =" title" v-model =" selected" >
4
+ <template #search =" {attributes , events } " >
5
+ <input
6
+ :required =" !selected"
7
+ class =" vs__search"
8
+ v-bind =" attributes"
9
+ v-on =" events"
10
+ />
11
+ </template >
12
+ </v-select >
13
+
14
+ <input type =" submit" >
15
+ </form >
16
+ </template >
17
+
18
+ <script >
19
+ import books from ' ../data/books'
20
+ export default {
21
+ data : () => ({
22
+ books,
23
+ selected: null ,
24
+ }),
25
+ methods: {
26
+ onSubmit () {
27
+ alert (' Submitted!' );
28
+ }
29
+ }
30
+ };
31
+ </script >
32
+
33
+ <style scoped>
34
+ form {
35
+ display : flex ;
36
+ align-items : stretch ;
37
+ }
38
+
39
+ .v-select {
40
+ width : 75% ;
41
+ }
42
+
43
+ input [type = " submit" ] {
44
+ margin-left : 1rem ;
45
+ background : #44ae7d ;
46
+ border : none ;
47
+ border-radius : 3px ;
48
+ color : #fff ;
49
+ width : 20% ;
50
+ }
51
+ </style >
Original file line number Diff line number Diff line change @@ -117,6 +117,7 @@ module.exports = {
117
117
title : 'Digging Deeper' ,
118
118
collapsable : false ,
119
119
children : [
120
+ [ 'guide/validation' , 'Validation' ] ,
120
121
[ 'guide/vuex' , 'Vuex' ] ,
121
122
[ 'guide/ajax' , 'AJAX' ] ,
122
123
] ,
Original file line number Diff line number Diff line change
1
+ ## Required
2
+
3
+ If you need to ensure that a selection is made before a form is submitted, you can
4
+ use the ` required ` attribute in combination with the ` search ` scoped slot in order
5
+ to do so.
6
+
7
+ However, the ` search ` input within the component does not actually store a value, so
8
+ simply adding the ` required ` attribute won't work. Instead, we'll bind the attribute
9
+ dynamically, so that it's only present if we don't have a selection.
10
+
11
+ <ValidationRequired />
12
+
13
+ ``` html
14
+ <v-select :options =" books" label =" title" v-model =" selected" >
15
+ <template #search =" {attributes, events}" >
16
+ <input
17
+ class =" vs__search"
18
+ :required =" !selected"
19
+ v-bind =" attributes"
20
+ v-on =" events"
21
+ />
22
+ </template >
23
+ </v-select >
24
+ ```
You can’t perform that action at this time.
0 commit comments