Clone HTML element without clone event

Asked

Viewed 38 times

0

I possess in my HTML a form I use for "mock" I mean, he’s just meant to be clonado to other places.

After the first cloning I change some inputs so that they use a plugin datetimepicker but after trying to clone for a second time the input datetimepicker always refers to the previous clone.

$("#addPriceList").on('click', function () {
    $('.box-list-price-form').slideDown();

    let cloned = $('.list-price-form-mock').last().clone({
      withDataAndEvents: false,
    });

    /**
     * Adiciona o plugin de datetimepicker aos elementos clonados
     */
    $.map($(cloned).find('.datep'), function(element) {
      $(element).datetimepicker({
          format: 'DD/MM/YYYY HH:mm:ss',
          locale: 'pt-BR'
      });
    });

    $(cloned).removeClass('is-hidden').appendTo('.price-forms form');
});

That is, when clon for the second time the second input of datetimepicker is pointing to the previous clone, I am changing the input from the previous clone instead of the current clone. How do I remove this association? have tried withDateAndEvents: false but it didn’t work.

  • I don’t understand the function of $.map. Only the $(cloned).find('.datep') already takes all elements at once.

  • I made a test here based on your code and it worked normal, IE, each cloned input was with its own datetimepicker.

No answers

Browser other questions tagged

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