DubFriend / jquery.repeater

Create a repeatable group of input elements
MIT License
389 stars 191 forks source link

Improve documentation on hide elements #93

Open viniciusbig opened 6 years ago

viniciusbig commented 6 years ago

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();
        });
    }
},
jigapate commented 3 years ago

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

cawecoy commented 3 years ago

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

firecall commented 3 years ago

@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));
          });
      });
},