Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

283
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda