Feat(ButtonAddLine): Añadir linea de venta en formulario WIP

This commit is contained in:
2024-07-12 23:40:43 -05:00
parent 6795aa3dcc
commit a63ae668a2
2 changed files with 32 additions and 7 deletions

View File

@@ -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;
});
});