Merge pull request #34508 from iamejaaz/fix-duplicate-row

fix: duplicate row button visible on cant add rows
This commit is contained in:
Ejaaz Khan 2025-10-28 14:15:14 +05:30 committed by GitHub
commit e0c43e3abb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -87,7 +87,7 @@ export default class Grid {
data-action="delete_rows">
${__("Delete")}
</button>
<button type="button" class="btn btn-xs btn-secondary grid-remove-rows hidden"
<button type="button" class="btn btn-xs btn-secondary hidden grid-duplicate-row"
data-action="duplicate_rows">
${__("Duplicate Row")}
</button>
@ -136,6 +136,7 @@ export default class Grid {
this.grid_custom_buttons = this.wrapper.find(".grid-custom-buttons");
this.remove_rows_button = this.grid_buttons.find(".grid-remove-rows");
this.remove_all_rows_button = this.grid_buttons.find(".grid-remove-all-rows");
this.duplicate_row_button = this.grid_buttons.find(".grid-duplicate-row");
this.setup_allow_bulk_edit();
this.setup_check();
@ -219,6 +220,7 @@ export default class Grid {
this.last_checked_docname = docname;
}
this.refresh_remove_rows_button();
this.refresh_duplicate_rows_button();
});
}
@ -340,6 +342,22 @@ export default class Grid {
100
);
refresh_duplicate_rows_button() {
if (this.df.cannot_add_rows) {
return;
}
this.duplicate_row_button.toggleClass(
"hidden",
this.wrapper.find(".grid-body .grid-row-check:checked:first").length ? false : true
);
}
debounced_duplicate_rows_button = frappe.utils.debounce(
this.refresh_duplicate_rows_button,
100
);
get_selected() {
return (this.grid_rows || [])
.map((row) => {
@ -531,7 +549,9 @@ export default class Grid {
// show, hide buttons to add rows
if (this.cannot_add_rows || (this.df && this.df.cannot_add_rows)) {
// add 'hidden' to buttons
this.wrapper.find(".grid-add-row, .grid-add-multiple-rows").addClass("hidden");
this.wrapper
.find(".grid-add-row, .grid-add-multiple-rows, .grid-duplicate-row")
.addClass("hidden");
} else {
// show buttons
this.wrapper.find(".grid-add-row").removeClass("hidden");