Home > Enterprise >  multiple input clone jquery without value and datepicker problem
multiple input clone jquery without value and datepicker problem

Time:01-11

Hi this is my code for clone from multiple inputs

<div style="margin-top: 10px;" >
  <div >
<input type="text"  name="kala[]" placeholder="کالا" required>
</div>
<div >
<input type="text"  name="weight[]" placeholder="وزن خالص">
</div>
<div >
<input type="text"  name="date[]" placeholder="تاریخ">
</div>
<div >
<input type="text" placeholder="شماره قبض" name="receipt[]" >
</div>
<a ><i ></i></a>
</div>
<div ></div>


<script>
      $('.extra-fields-customer').click(function() {
            $('.customer_records').clone().appendTo('.customer_records_dynamic');
            $('.customer_records_dynamic .customer_records').addClass('single remove');
            $('.single .extra-fields-customer').remove();
            $('.single').append('<a href="#" ><i ></i></a>');
            $('.customer_records_dynamic > .single').attr("class", "remove");
            $('.customer_records_dynamic').attr("value", "");
            $(this).find('input').val('').end();

      });


      $(document).on('click', '.remove-field', function(e) {
            $(this).parent('.remove').remove();
            e.preventDefault();
      });
      $(".date").persianDatepicker({
            showGregorianDate: false,
            formatDate: "YYYY-0M-0D"
      });
</script>

This is my problem with this code I want the value to be empty when it clones a row And do not take the amount of the first input

And another problem I have is that only my first input accepts the date and the simulated inputs do not show the date selector

CodePudding user response:

You should assign a variable for your clone so you can run a couple methods on it after the fact

$clone = $('.customer_records').clone().appendTo('.customer_records_dynamic');

This is my problem with this code I want the value to be empty when it clones a row And do not take the amount of the first input

You should be able to then do something like this

$clone.find('input').val('');

And another problem I have is that only my first input accepts the date and the simulated inputs do not show the date selector

This is because the new date control is created after that initialization script runs. Not sure if you can create a delegate for that, so you might want to just run the init directly on it, like

  $clone.find('input.date').persianDatepicker({
        showGregorianDate: false,
        formatDate: "YYYY-0M-0D"
  });
  •  Tags:  
  • Related