I have a repeated fieldset in jquery where users can add and remove items. Each repeated element contain a set of selects and textfields. The repeated element appears when a specific value (1) is selected in a radio button. Users can repeat the area after clicking on the right value, and then can replicate the fieldset every times they want just clicking the + icon, and remove with the - icon. What I need is that if the user that previously added some repeated dataset changes the radio value to 0, all the replicated fieldsets disappear, using the same replication function.
Repeating buttons:
<a class="deleteGroup" href="#">
<i data-isicon="true" class="icon-minus Tip tip-small" data-role="_delete_group" opts="{"trigger": "hover"}" data-original-title=""></i></a>
<a class="addGroup" href="#">
<i data-isicon="true" class="icon-plus Tip tip-small" data-role="_duplicate_group" opts="{"trigger": "hover"}" data-original-title=""></i></a>
jquery
var livelloStudio = jQuery("input[name='iscritti___livelloIstruzione[]']:checked").val();
if(livelloStudio == '0') {
jQuery('.deleteGroup').each(function() {
console.log("how many repeat?");
jQuery(".deleteGroup").click();
});
jQuery('#group25').hide();
}
The code seems to work just one time: it correctly trigger the click just for the first element. I cannot understand why: I can see the console.log repeating the string n times when n is the number of items added by user... so I expected to see the click action repeated on every element with "deleteGroup" class applied.
Can you see what is wrong? Thanks!