Crud fixed
This commit is contained in:
@@ -46,17 +46,17 @@ const hideDialog = () => {
|
||||
|
||||
const saveProduct = () => {
|
||||
submitted.value = true;
|
||||
if (product.value.name.trim()) {
|
||||
if (product.value.name && product.value.name.trim() && product.value.price) {
|
||||
if (product.value.id) {
|
||||
product.value.inventoryStatus = product.value.inventoryStatus.value ? product.value.inventoryStatus.value : product.value.inventoryStatus;
|
||||
product.value[findIndexById(product.value.id)] = product.value;
|
||||
products.value[findIndexById(product.value.id)] = product.value;
|
||||
toast.add({ severity: 'success', summary: 'Successful', detail: 'Product Updated', life: 3000 });
|
||||
} else {
|
||||
product.value.id = createId();
|
||||
product.value.code = createId();
|
||||
product.value.image = 'product-placeholder.svg';
|
||||
product.value.inventoryStatus = product.value.inventoryStatus ? product.value.inventoryStatus.value : 'INSTOCK';
|
||||
products.value.push(product);
|
||||
products.value.push(product.value);
|
||||
toast.add({ severity: 'success', summary: 'Successful', detail: 'Product Created', life: 3000 });
|
||||
}
|
||||
productDialog.value = false;
|
||||
@@ -193,7 +193,7 @@ const initFilters = () => {
|
||||
<Column field="category" header="Category" :sortable="true" headerStyle="width:14%; min-width:10rem;">
|
||||
<template #body="slotProps">
|
||||
<span class="p-column-title">Category</span>
|
||||
{{ formatCurrency(slotProps.data.category) }}
|
||||
{{ slotProps.data.category }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="rating" header="Reviews" :sortable="true" headerStyle="width:14%; min-width:10rem;">
|
||||
@@ -270,7 +270,8 @@ const initFilters = () => {
|
||||
<div class="formgrid grid">
|
||||
<div class="field col">
|
||||
<label for="price">Price</label>
|
||||
<InputNumber id="price" v-model="product.price" mode="currency" currency="USD" locale="en-US" />
|
||||
<InputNumber id="price" v-model="product.price" mode="currency" currency="USD" locale="en-US" :class="{ 'p-invalid': submitted && !product.price }" :required="true" />
|
||||
<small class="p-invalid" v-if="submitted && !product.price">Price is required.</small>
|
||||
</div>
|
||||
<div class="field col">
|
||||
<label for="quantity">Quantity</label>
|
||||
|
||||
Reference in New Issue
Block a user