1111 <form v-if =" !loading" @submit.prevent =" onSubmit" >
1212 <div class =" grid grid-cols-3" >
1313 <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'] " />
2020 </div >
2121 <div class =" col-span-1 px-4 pt-5 pb-4" >
2222 <image-preview v-model =" product.images"
@@ -72,10 +72,12 @@ const product = ref({
7272 description: ' ' ,
7373 price: null ,
7474 quantity: null ,
75- published: null ,
75+ published: false ,
7676 categories: []
7777})
7878
79+ const errors = ref ({});
80+
7981const loading = ref (false )
8082const options = ref ([])
8183
@@ -99,6 +101,7 @@ onMounted(() => {
99101
100102function onSubmit ($event , close = false ) {
101103 loading .value = true
104+ errors .value = {};
102105 product .value .quantity = product .value .quantity || null
103106 if (product .value .id ) {
104107 store .dispatch (' updateProduct' , product .value )
@@ -113,6 +116,10 @@ function onSubmit($event, close = false) {
113116 }
114117 }
115118 })
119+ .catch (err => {
120+ loading .value = false ;
121+ errors .value = err .response .data .errors
122+ })
116123 } else {
117124 store .dispatch (' createProduct' , product .value )
118125 .then (response => {
@@ -131,7 +138,7 @@ function onSubmit($event, close = false) {
131138 })
132139 .catch (err => {
133140 loading .value = false ;
134- debugger ;
141+ errors . value = err . response . data . errors
135142 })
136143 }
137144}
0 commit comments