jquery.repeater icon indicating copy to clipboard operation
jquery.repeater copied to clipboard

Improve documentation on hide elements

Open viniciusbig opened this issue 6 years ago • 3 comments

The README show an example of the hide callback which is optional

hide: function (deleteElement) {
    if(confirm('Are you sure you want to delete this element?')) {
        $(this).slideUp(deleteElement);
    }
},

But the jQuery slideUp function doesn't actually delete the DOM element and the $('.repeater').repeaterVal(); method get a wrong dataset, with the deleted data.

The better approach should use the $.remove.

In order to keep the slideUp animation, the example should be:

hide: function (deleteElement) {
    if(confirm('Are you sure you want to delete this element?')) {
        $(this).slideUp(deleteElement, function() {
            $(this).remove();
        });
    }
},

viniciusbig avatar Aug 06 '18 01:08 viniciusbig

@viniciusbig , did you faced a problem that values of detected items was still there? #141 I have the same kind of issue i think,

jigapate avatar Dec 23 '20 09:12 jigapate

@viniciusbig but the index of input array name only gets automatically resorted when using exactly $(this).slideUp(deleteElement); and I don't know why

cawecoy avatar Apr 16 '21 15:04 cawecoy

@viniciusbig but the index of input array name only gets automatically resorted when using exactly $(this).slideUp(deleteElement); and I don't know why

I'm having the same issue as OP.

However I'm also manually renaming the inputs anyway to be compatible with my the form processor being used.

jQuery example:

hide: function (deleteElement) {
      $(this).slideUp(deleteElement, function() {
        $(this).remove();
          $('.item').each(function(i) {
            $(this).attr('name', 'item: ' + (i+1));
          });
      });
},

firecall avatar Jul 13 '21 03:07 firecall