Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Fix bug #142 #151

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/webapp/view/jsp/management/order/add-order.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@
{ label: "${customer.name}", value: "${customer.ID}" },
</c:forEach>
];

customerNameInput.on('input', function () {
var inputText = $(this).val().trim().toLowerCase();
var matchedCustomer = customers.find(function (customer) {
return customer.label.toLowerCase() === inputText;
});

if (matchedCustomer) {
customerIdInput.val(matchedCustomer.value);
} else {
customerIdInput.val('');
}
});

customerNameInput.autocomplete({
source: function (request, response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

</head>

<body id="page-top">
<body id="page-top" class="d-flex flex-column min-vh-100">
<div id="wrapper">
<%@include file="../../../common/_sidenav.jsp" %>
<div class="d-flex flex-column" id="content-wrapper">
Expand Down Expand Up @@ -123,28 +123,59 @@
<!--Danh sach goi y-->
<script>
$(document).ready(function () {
var availableProducts = [
var productsArray = [
<c:forEach var="product" items="${requestScope.products}">
"${product.name}",
{ name: "${product.name}", ID: "${product.ID}", price: "${product.price}" },
</c:forEach>
];

$("#product-name").autocomplete({
source: availableProducts,
select: function( event, ui ) {
var selectedProduct = ui.item.value;
<c:forEach var="product" items="${requestScope.products}">
if("${product.name}" === selectedProduct) {
$('#product-id').val("${product.ID}");
$('#product-price').val(formatCurrency("${product.price}"));
$('#product-quantity').val(1);
}
</c:forEach>
calculateTotal();
source: function(request, response) {
var term = request.term.toLowerCase();
var filteredProducts = productsArray.filter(function(product) {
return product.name.toLowerCase().includes(term);
});
response(filteredProducts.map(function(product) {
return product.name;
}));
},
select: function (event, ui) {
var selectedProductName = ui.item.value;
var selectedProduct = findProductByName(selectedProductName);
if (selectedProduct) {
$('#product-id').val(selectedProduct.ID);
$('#product-price').val(formatCurrency(selectedProduct.price));
$('#product-quantity').val(1);
calculateTotal();
}
},
change: function (event, ui) {
var enteredProductName = $(this).val();
var enteredProduct = findProductByName(enteredProductName);

if (enteredProduct) {
$('#product-id').val(enteredProduct.ID);
$('#product-price').val(formatCurrency(enteredProduct.price));
$('#product-quantity').val(1);
calculateTotal();
} else {
$('#product-id').val('');
$('#product-price').val('');
$('#product-quantity').val('');
$('#product-total-price').val('');
}
}
});

function findProductByName(productName) {
return productsArray.find(function(product) {
return product.name === productName;
});
}
});
</script>


<!--Validate input-->
<script>
//Validate form add product into order
Expand Down
Loading