Dynamic form locking select

Asked

Viewed 55 times

0

I have a dynamic form (that) with two fields (a SELECT and a quantity input), but every time I add two more fields SELECT gets stuck.

$(document).ready(function(){
var itemCont = 1;
$("#novoProd").click(function(){
  var novoItem = $("#item").clone();
  // modifica o id do item recem criado
  $(novoItem).attr("id","item"+itemCont);
  var novoSelect = $(novoItem).children()[1];
  $(novoSelect).attr("id","produtoId"+itemCont);
  $(novoSelect).attr("name","produtoId[]"+itemCont);

  var novoSelect = $(novoItem).children()[3];
  $(novoSelect).attr("id","quant"+itemCont);
  $(novoSelect).attr("name","quant[]"+itemCont);

  $("#formulario").append(novoItem);
  itemCont++;
  $("#itemCont").val(itemCont);
});

I’m using the plugin Chosen to create the search field in SELECT, without it the form works normal.

<select data-placeholder="Choose a Country..." class="chosen-select"  id="produtoId" name="produtoId[]">
  • What do you mean "stay locked"?

  • Check for an error in the console.

  • @dvd, SELECT options do not appear.

  • @We step, does not point out any error.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.