Feat(ButtonAddLine): Añadir linea de venta en formulario WIP
This commit is contained in:
		
							
								
								
									
										18
									
								
								tienda_ilusion/don_confiao/static/js/add_line.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								tienda_ilusion/don_confiao/static/js/add_line.js
									
									
									
									
									
										Normal 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; | ||||||
|  |   }); | ||||||
|  | }); | ||||||
| @@ -1,12 +1,19 @@ | |||||||
| <!doctype html> | <!doctype html> | ||||||
|  | {% load static %} | ||||||
| <form method="POST"> | <form method="POST"> | ||||||
|   {% csrf_token %} |   {% csrf_token %} | ||||||
|   {{ sale_form}} |   {{ sale_form}} | ||||||
|   {{ linea_formset.management_form }} |   {{ linea_formset.management_form }} | ||||||
|  |   <div id="formset-container"> | ||||||
|     {% for form in linea_formset %} |     {% for form in linea_formset %} | ||||||
|  |       <div class="form-container"> | ||||||
|         <table style="border: solid 1px blue; margin: 10px"> |         <table style="border: solid 1px blue; margin: 10px"> | ||||||
|           {{ form.as_table }} |           {{ form.as_table }} | ||||||
|         </table> |         </table> | ||||||
|  |       </div> | ||||||
|     {% endfor %} |     {% endfor %} | ||||||
|  |   </div> | ||||||
|  |   <button id="add_line">Añadir Linea</button> | ||||||
|   <br/><button name="form" type="submit" >Comprar</button> |   <br/><button name="form" type="submit" >Comprar</button> | ||||||
|  |   <script src="{% static 'js/add_line.js' %}"></script> | ||||||
| </form> | </form> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user