File tree Expand file tree Collapse file tree 3 files changed +39
-11
lines changed
Expand file tree Collapse file tree 3 files changed +39
-11
lines changed Original file line number Diff line number Diff line change 4040 isEditing () {
4141 return this .category .id > 0
4242 },
43+ isValid () {
44+ this .resetMessages ()
45+ if (this .category .name === ' ' ) {
46+ this .setMessage ({ type: ' error' , message: [' Please fill category name' ] })
47+ return false
48+ }
49+ return true
50+ },
4351 },
4452
4553 methods: {
7280 })
7381 }
7482 },
75- isValid () {
76- this .resetMessages ()
77- if (this .category .name === ' ' ) {
78- this .setMessage ({ type: ' error' , message: [' Please fill category name' ] })
79- return false
80- }
81- return true
82- },
8383 submit () {
8484 /**
8585 * Pre-conditions are met
8686 */
87- if (this .isValid () ) {
87+ if (this .isValid ) {
8888 /**
8989 * Shows the global spinner
9090 */
124124 })
125125 },
126126 update () {
127- this .$http .put (` categories/${ this .category .id } /update` , { category : this .category } ).then (() => {
127+ this .$http .put (` categories/${ this .category .id } /update` , this .category ).then (() => {
128128 /**
129129 * This event will notify the world about
130130 * the category creation. In this case
Original file line number Diff line number Diff line change 11
22<script >
33 import { mapState , mapActions } from ' vuex'
4+ import { isEmpty } from ' lodash'
45
56 export default {
67 computed: {
1112 hasErrorMessages () {
1213 return this .messages .error .length > 0
1314 },
15+ hasValidationMessages () {
16+ return ! isEmpty (this .messages .validation )
17+ },
1418 },
1519 methods: {
1620 ... mapActions ([' setMessage' ]),
1721 dismiss (type ) {
1822 let obj
1923 if (type === ' error' ) {
2024 obj = { type, message: [] }
25+ } else if (type === ' validation' ) {
26+ obj = { type, message: {} }
2127 } else {
2228 obj = { type, message: ' ' }
2329 }
4854 </ul >
4955 </div >
5056
57+ <!-- Validation messages -->
58+ <div class =" alert alert-danger" v-show =" hasValidationMessages" >
59+ <button type =" button" class =" close" aria-label =" Close" @click =" dismiss('validation')" >
60+ <span aria-hidden =" true" >× ; </span >
61+ </button >
62+ <ul >
63+ <li v-for =" error in messages.validation" >{{ error[0] }}</li >
64+ </ul >
65+ </div >
66+
5167 </div >
5268</template >
Original file line number Diff line number Diff line change 11import axios from 'axios'
2+ import { isArray } from 'lodash'
23import store from '../store'
34import router from '../router'
45import { apiUrl } from '../config'
@@ -30,7 +31,18 @@ http.interceptors.response.use(
3031 if ( error . response . data . reason === 'token' ) {
3132 router . push ( { name : 'login.index' } )
3233 }
33- store . dispatch ( 'setMessage' , { type : 'error' , message : error . response . data . messages } )
34+ /**
35+ * Error messages are sent in arrays
36+ */
37+ if ( isArray ( error . response . data ) ) {
38+ store . dispatch ( 'setMessage' , { type : 'error' , message : error . response . data . messages } )
39+ /**
40+ * Laravel generated validation errors are
41+ * sent in an object
42+ */
43+ } else {
44+ store . dispatch ( 'setMessage' , { type : 'validation' , message : error . response . data } )
45+ }
3446 store . dispatch ( 'setFetching' , { fetching : false } )
3547 return Promise . reject ( error )
3648 }
You can’t perform that action at this time.
0 commit comments