Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

280
Vistas
In Django, how to modify field names in dynamic forms using Java Script

I created a form. Using jQuery got first para of form. Using add function I am adding it again. With this I am getting same names for all the new fields. I am not able to retrieve its values in views.py.

Is there any way to change form field names in js? or any other solution to it?

JS Function:

$(".add").click(function() {
    $("form > p:first-of-type").clone(true).insertBefore("form > p:last-child");
    return false;
});

$(".remove").click(function() {
    $(this).parent().remove();
});

With this JS I am cloning this lines,

<input type="text" name="med" maxlength="100" required id="id_medicine">

While sending it back, I need to change name of the input field(med to med1). So, that I can fetch all values in views.py

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are just cloning what is there on first para of form, use input name as array and use different empty inputs with same array name when adding of next para. for eg-

<div class="row">
 <input type="text" name="arr1[]" >
 <input type="text" name="arr2[]" > 
</div>
<button id="add"> Add</button>
    
  $('#add').click(function(){
    
      $('.row').append('<input type="text" name="arr1[]" ><input type="text" name="arr2[]">');
    })
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda