From b9754a8af6bcc33a43a5cd5cc2eec8d789cac7ee Mon Sep 17 00:00:00 2001 From: FazeElian Date: Sun, 4 Feb 2024 16:15:27 -0500 Subject: [PATCH] =?UTF-8?q?Ajuste=20bot=C3=B3n:=20Eliminar=20fila=20de=20p?= =?UTF-8?q?roducto=20al=20registrar=20nueva=20venta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/views/Admin/sale/form.blade.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/resources/views/Admin/sale/form.blade.php b/resources/views/Admin/sale/form.blade.php index b27164b..b6a484a 100644 --- a/resources/views/Admin/sale/form.blade.php +++ b/resources/views/Admin/sale/form.blade.php @@ -49,6 +49,7 @@ // Agregar la clase "filas-datos" al nuevo elemento newRow.classList.add("filas-datos"); + const productName = newRow.insertCell(0); const productQuantity = newRow.insertCell(1); const productPrice = newRow.insertCell(2); @@ -88,7 +89,7 @@ productPrice.className = "item-fila precio-prod"; // deleteRowBtn.innerHTML = ''; - deleteRowBtn.innerHTML = 'Eliminar Producto'; + deleteRowBtn.innerHTML = 'Eliminar Producto'; deleteRowBtn.className = "item-fila elim-fila-dato"; }); @@ -99,15 +100,19 @@ function removeRow(button){ // Elimina la fila row.remove(); } + // Agregar un evento de cambio al select generado dinĂ¡micamente document.addEventListener('change', function(event) { const target = event.target; + // Verificar si el elemento cambiado es un select de producto if (target && target.tagName === 'SELECT' && target.name === 'product_id[]') { const selectedProductId = target.value; const priceField = target.parentNode.nextElementSibling.nextElementSibling.querySelector('input[name="price[]"]'); + // Buscar el producto seleccionado en la lista de productos disponibles const selectedProduct = {!! json_encode($products) !!}.find(product => product.id == selectedProductId); + // Actualizar el campo de precio con el precio del producto seleccionado if (selectedProduct) { priceField.value = selectedProduct.price;