From 3e35807a87ffdc59435f4fcce73079d341ac4b87 Mon Sep 17 00:00:00 2001 From: Rodia Date: Sat, 13 Jul 2024 11:01:11 -0500 Subject: [PATCH 1/2] Feat(AddSaleLineButton): Sale Line Button --- tienda_ilusion/don_confiao/static/js/add_line.js | 2 +- tienda_ilusion/don_confiao/templates/don_confiao/purchase.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tienda_ilusion/don_confiao/static/js/add_line.js b/tienda_ilusion/don_confiao/static/js/add_line.js index aed4bec..bfb38ed 100644 --- a/tienda_ilusion/don_confiao/static/js/add_line.js +++ b/tienda_ilusion/don_confiao/static/js/add_line.js @@ -1,7 +1,7 @@ document.addEventListener('DOMContentLoaded', function(){ var button = document.getElementById('add_line'); var formContainer = document.getElementById('formset-container'); - var totalForms = document.getElementById('id_form-TOTAL_FORMS'); + var totalForms = document.getElementById('id_saleline_set-TOTAL_FORMS'); button.addEventListener('click', function(){ // Clonar un formulario vacío var newForm = formContainer.querySelector('.form-container').cloneNode(true); diff --git a/tienda_ilusion/don_confiao/templates/don_confiao/purchase.html b/tienda_ilusion/don_confiao/templates/don_confiao/purchase.html index 7f6c8d9..d174357 100644 --- a/tienda_ilusion/don_confiao/templates/don_confiao/purchase.html +++ b/tienda_ilusion/don_confiao/templates/don_confiao/purchase.html @@ -13,7 +13,7 @@ {% endfor %} - +
From 9ecd94912317c41db1a6751bfa109e1a293fcb49 Mon Sep 17 00:00:00 2001 From: Rodia Date: Sat, 13 Jul 2024 11:25:12 -0500 Subject: [PATCH 2/2] Feat(ReplaceNameIdSaleLine) --- .../don_confiao/static/js/add_line.js | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tienda_ilusion/don_confiao/static/js/add_line.js b/tienda_ilusion/don_confiao/static/js/add_line.js index bfb38ed..4f6bc25 100644 --- a/tienda_ilusion/don_confiao/static/js/add_line.js +++ b/tienda_ilusion/don_confiao/static/js/add_line.js @@ -3,16 +3,27 @@ document.addEventListener('DOMContentLoaded', function(){ var formContainer = document.getElementById('formset-container'); var totalForms = document.getElementById('id_saleline_set-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 + + var fields = newForm.querySelectorAll('[id^="id_saleline_set-"], [name^="saleline_set-"]'); + fields.forEach(function(field) { + var oldId = field.id; + var oldName = field.name; + + if (oldId) { + var newId = oldId.replace(/-\d+-/, '-' + formCount + '-'); + field.id = newId; + } + if (oldName) { + var newName = oldName.replace(/-\d+-/, '-' + formCount + '-'); + field.name = newName; + } + }); + formContainer.appendChild(newForm); - // Incrementar el total de formularios totalForms.value = formCount + 1; }); });