File tree Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Original file line number Diff line number Diff line change 10
10
</div >
11
11
<div class =" three columns" >
12
12
<label for =" name" >Name</label >
13
- <input name =" name" type =" text" v-model =" name" @keyup.enter =" add" >
13
+ <input name =" name" type =" text" ref = " name " v-model =" name" @keyup.enter =" add" >
14
14
</div >
15
15
<div class =" one columns" >
16
- <button class =" button-primary" @click =" add" >Add</button >
16
+ <button class =" button-primary" :disabled = " blankName " @click =" add" >Add</button >
17
17
</div >
18
18
</div >
19
19
</template >
@@ -26,13 +26,24 @@ module.exports = {
26
26
type: ' dice' ,
27
27
}
28
28
},
29
+ computed: {
30
+ blankName : function () {
31
+ return this .name .trim ().length == 0
32
+ }
33
+ },
29
34
methods: {
30
35
add : function () {
31
- this .$emit (' add' , {
32
- name: this .name ,
33
- type: this .type
34
- })
36
+ if (! this .blankName ) {
37
+ this .$emit (' add' , {
38
+ name: this .name .trim (),
39
+ type: this .type
40
+ })
41
+ this .name = ' '
42
+ }
35
43
}
44
+ },
45
+ mounted : function () {
46
+ this .$refs .name .focus ()
36
47
}
37
48
}
38
49
</script >
@@ -45,4 +56,11 @@ module.exports = {
45
56
button {
46
57
margin-top : 2.9rem ;
47
58
}
59
+ button [disabled ] {
60
+ opacity : 0.5 ;
61
+ }
62
+ button [disabled ]:hover {
63
+ background-color : #33C3F0 ;
64
+ border-color : #33C3F0 ;
65
+ }
48
66
</style >
You can’t perform that action at this time.
0 commit comments