0
I’m doing maintenance on a system, and I found the following code:
$(".MinhaClass").die();
$(".MinhaClass").live('click', function () {
// Código
}
.MinhaClass
refers to a list of checkbox
. I was tasked to add at the beginning of the list a checkbox
to select All the list items. I soon thought about doing:
$("#selecionar-todos").change(function () {
$('#lista input:checkbox').each(function () {
$(this).click();
});
});
Soon the system would behave the same way as before, without many changes.
When you click on all, all items in the list are checked, including the "Select All" checkbox itself, but when you click on an item individually, it is unchecked and the "Select All" checkbox must also be unchecked.
For this, it would be necessary to identify in the first code where the click action comes from, if it was called by the method I created or if it was triggered by the mouse click individually.
I have this Fiddle to explain better.
Note: The problem is that the Select All checkbox should only be marked when all items are marked, if any unchecked, checkbox select all also must be unchecked...
It doesn’t make much sense when clicked on an individually uncheck the rest once it has already been clicked on all, image if it was a huge list where the user wanted to mark all and then uncheck only one... but well, as the rules of the game is not ours...
– Marco Souza