Skip to content

Commit d982c9d

Browse files
authored
Merge pull request #5857 from Laravel-Backpack/fix-bulk-buttons
Fix Bulk Actions in v7
2 parents 6e6c038 + ef85577 commit d982c9d

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/resources/views/crud/columns/inc/bulk_actions_checkbox.blade.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
// make sure all other main checkboxes have the same checked status
148148
mainCheckboxes.forEach(elem => elem.checked = checkbox.checked);
149149
150+
// Ensure buttons are updated after mass checkbox changes
151+
window.crud.enableOrDisableBulkButtons(tableId);
152+
150153
event.stopPropagation();
151154
};
152155
});
@@ -174,16 +177,38 @@
174177
const hasBulkActions = tableElement.getAttribute('data-has-bulk-actions') === 'true' ||
175178
tableElement.getAttribute('data-has-bulk-actions') === '1';
176179
177-
// Find all bulk buttons
178-
const tableWrapper = document.getElementById(`${tableId}_wrapper`);
179-
const bulkButtons = tableWrapper.querySelectorAll('.bulk-button');
180+
// Find all bulk buttons - search in table-specific locations first
181+
let bulkButtons = [];
182+
183+
const tableSpecificContainers = [
184+
document.querySelector(`#bottom_buttons_${tableId}`),
185+
document.querySelector(`#datatable_button_stack_${tableId}`)
186+
];
187+
188+
for (const container of tableSpecificContainers) {
189+
if (container) {
190+
const containerButtons = container.querySelectorAll('.bulk-button');
191+
if (containerButtons.length > 0) {
192+
bulkButtons = containerButtons;
193+
break;
194+
}
195+
}
196+
}
197+
198+
if (bulkButtons.length === 0) {
199+
const tableWrapper = document.getElementById(`${tableId}_wrapper`);
200+
if (tableWrapper) {
201+
bulkButtons = tableWrapper.querySelectorAll('.bulk-button');
202+
}
203+
}
180204
181205
// Update all buttons based on selection state
182206
bulkButtons.forEach(btn => {
183207
if (hasSelectedItems) {
184208
btn.classList.remove('disabled');
209+
btn.removeAttribute('disabled');
185210
186-
if (btn.hasAttribute('onclick') && !btn._onclickReplaced) {
211+
if (btn.hasAttribute('onclick') && !btn._onclickReplaced) {
187212
const originalOnclick = btn.getAttribute('onclick');
188213
189214
// Remove the original onclick attribute
@@ -216,6 +241,7 @@
216241
}
217242
} else {
218243
btn.classList.add('disabled');
244+
btn.setAttribute('disabled', 'disabled');
219245
}
220246
});
221247
}

0 commit comments

Comments
 (0)