diff --git a/tienda_ilusion/don_confiao/static/js/add_line.js b/tienda_ilusion/don_confiao/static/js/add_line.js new file mode 100644 index 0000000..aed4bec --- /dev/null +++ b/tienda_ilusion/don_confiao/static/js/add_line.js @@ -0,0 +1,18 @@ +document.addEventListener('DOMContentLoaded', function(){ + var button = document.getElementById('add_line'); + var formContainer = document.getElementById('formset-container'); + var totalForms = document.getElementById('id_form-TOTAL_FORMS'); + button.addEventListener('click', function(){ + // Clonar un formulario vacío + var newForm = formContainer.querySelector('.form-container').cloneNode(true); + // Obtener el número actual de formularios + var formCount = parseInt(totalForms.value); + // Actualizar los atributos de los nuevos campos del formulario + var regex = new RegExp('__prefix__', 'g'); + newForm.innerHTML = newForm.innerHTML.replace(regex, formCount); + // Añadir el nuevo formulario al contenedor + formContainer.appendChild(newForm); + // Incrementar el total de formularios + totalForms.value = formCount + 1; + }); +}); diff --git a/tienda_ilusion/don_confiao/templates/don_confiao/purchase.html b/tienda_ilusion/don_confiao/templates/don_confiao/purchase.html index 0d2c2f4..7f6c8d9 100644 --- a/tienda_ilusion/don_confiao/templates/don_confiao/purchase.html +++ b/tienda_ilusion/don_confiao/templates/don_confiao/purchase.html @@ -1,12 +1,19 @@ +{% load static %}