Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajuste botón: Eliminar fila de producto al registrar nueva venta #101

Merged
merged 1 commit into from
Feb 4, 2024
Merged
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
7 changes: 6 additions & 1 deletion resources/views/Admin/sale/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

// Agregar la clase "filas-datos" al nuevo elemento <tr>
newRow.classList.add("filas-datos");

const productName = newRow.insertCell(0);
const productQuantity = newRow.insertCell(1);
const productPrice = newRow.insertCell(2);
Expand Down Expand Up @@ -88,7 +89,7 @@
productPrice.className = "item-fila precio-prod";

// deleteRowBtn.innerHTML = '<td class="item-fila elim-fila-dato"><button type="button" onclick="removeRow(this)">Eliminar</button></td>';
deleteRowBtn.innerHTML = '<td><img src="{{ asset("assets/img/Admin/modules/icono-eliminar-rojo.png") }}" alt="Eliminar Producto"></td>';
deleteRowBtn.innerHTML = '<td><img src="{{ asset("assets/img/Admin/modules/icono-eliminar-rojo.png") }}" alt="Eliminar Producto" onclick="removeRow(this)"></td>';
deleteRowBtn.className = "item-fila elim-fila-dato";
});

Expand All @@ -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;
Expand Down
Loading