1
+ <template >
2
+ <div >
3
+ <!-- Button trigger modal -->
4
+ <button type =" button" class =" btn btn-primary btn-lg" data-toggle =" modal" data-target =" #myModal" >
5
+ Create New Note
6
+ </button >
7
+
8
+ <!-- Modal -->
9
+ <div class =" modal fade" id =" myModal" tabindex =" -1" role =" dialog" aria-labelledby =" myModalLabel" >
10
+ <div class =" modal-dialog" role =" document" >
11
+ <div class =" modal-content" >
12
+ <div class =" modal-header" >
13
+ <button type =" button" class =" close" data-dismiss =" modal" aria-label =" Close" ><span aria-hidden =" true" >× ; </span ></button >
14
+ <h4 class =" modal-title" id =" myModalLabel" >Create New Note</h4 >
15
+ </div >
16
+ <div class =" modal-body" >
17
+ <p class =" alert alert-success" v-if =" success" v-text =" success" ></p >
18
+ <form action =" /note" method =" post" @submit.prevent =" createNote" @keydown =" clearError($event.target.name)" >
19
+ <div :class =" ['form-group', errors.name ? 'has-error' : '']" >
20
+ <label for =" name" >Note Name</label >
21
+ <input type =" text" name =" name" id =" name" class =" form-control" v-model =" note.name" >
22
+
23
+ <span class =" help text-danger" v-if =" errors.name" >{{ errors.name[0] }}</span >
24
+ </div >
25
+ <div :class =" ['form-group', errors.description ? 'has-error' : '']" >
26
+ <label for =" description" >Note Description</label >
27
+ <textarea name =" description" id =" description" class =" form-control" v-model =" note.description" ></textarea >
28
+
29
+ <span class =" help text-danger" v-if =" errors.description" >{{ errors.description[0] }}</span >
30
+ </div >
31
+ <button type =" submit" class =" btn btn-primary" >Create</button >
32
+ </form >
33
+ </div >
34
+ <div class =" modal-footer" >
35
+ <button type =" button" class =" btn btn-default" data-dismiss =" modal" >Close</button >
36
+ </div >
37
+ </div >
38
+ </div >
39
+ </div >
40
+ </div >
41
+ </template >
42
+
43
+ <script >
44
+ export default {
45
+ data : function () {
46
+ return {
47
+ note: {
48
+ name: ' ' ,
49
+ description: ' '
50
+ },
51
+ errors: [],
52
+ success: ' '
53
+ }
54
+ },
55
+ methods: {
56
+ createNote : function () {
57
+ let data = this .note ;
58
+
59
+ axios .post (' /note' , data)
60
+ .then (response => this .success = response .data .message )
61
+ .catch (error => this .errors = error .response .data );
62
+
63
+ this .note = { name: ' ' , description: ' ' };
64
+ },
65
+ clearError : function (field ) {
66
+ delete this .errors [field];
67
+ }
68
+ }
69
+ }
70
+ </script >
0 commit comments