11
11
<form v-if =" !loading" @submit.prevent =" onSubmit" >
12
12
<div class =" grid grid-cols-3" >
13
13
<div class =" col-span-2 px-4 pt-5 pb-4" >
14
- <CustomInput class =" mb-2" v-model =" product.title" label =" Product Title" />
15
- <CustomInput type =" richtext" class =" mb-2" v-model =" product.description" label =" Description" />
16
- <CustomInput type =" number" class =" mb-2" v-model =" product.price" label =" Price" prepend =" $" />
17
- <CustomInput type =" number" class =" mb-2" v-model =" product.quantity" label =" Quantity" />
18
- <CustomInput type =" checkbox" class =" mb-2" v-model =" product.published" label =" Published" />
19
- <treeselect v-model =" product.categories" :multiple =" true" :options =" options" />
14
+ <CustomInput class =" mb-2" v-model =" product.title" label =" Product Title" :errors = " errors['title'] " />
15
+ <CustomInput type =" richtext" class =" mb-2" v-model =" product.description" label =" Description" :errors = " errors['description'] " />
16
+ <CustomInput type =" number" class =" mb-2" v-model =" product.price" label =" Price" prepend =" $" :errors = " errors['price'] " />
17
+ <CustomInput type =" number" class =" mb-2" v-model =" product.quantity" label =" Quantity" :errors = " errors['quantity'] " />
18
+ <CustomInput type =" checkbox" class =" mb-2" v-model =" product.published" label =" Published" :errors = " errors['published'] " />
19
+ <treeselect v-model =" product.categories" :multiple =" true" :options =" options" :errors = " errors['categories'] " />
20
20
</div >
21
21
<div class =" col-span-1 px-4 pt-5 pb-4" >
22
22
<image-preview v-model =" product.images"
@@ -72,10 +72,12 @@ const product = ref({
72
72
description: ' ' ,
73
73
price: null ,
74
74
quantity: null ,
75
- published: null ,
75
+ published: false ,
76
76
categories: []
77
77
})
78
78
79
+ const errors = ref ({});
80
+
79
81
const loading = ref (false )
80
82
const options = ref ([])
81
83
@@ -99,6 +101,7 @@ onMounted(() => {
99
101
100
102
function onSubmit ($event , close = false ) {
101
103
loading .value = true
104
+ errors .value = {};
102
105
product .value .quantity = product .value .quantity || null
103
106
if (product .value .id ) {
104
107
store .dispatch (' updateProduct' , product .value )
@@ -113,6 +116,10 @@ function onSubmit($event, close = false) {
113
116
}
114
117
}
115
118
})
119
+ .catch (err => {
120
+ loading .value = false ;
121
+ errors .value = err .response .data .errors
122
+ })
116
123
} else {
117
124
store .dispatch (' createProduct' , product .value )
118
125
.then (response => {
@@ -131,7 +138,7 @@ function onSubmit($event, close = false) {
131
138
})
132
139
.catch (err => {
133
140
loading .value = false ;
134
- debugger ;
141
+ errors . value = err . response . data . errors
135
142
})
136
143
}
137
144
}
0 commit comments