Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove empty rows #26315

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion frappe/public/js/frappe/form/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ export default class Grid {
if (copy_doc) {
d = this.duplicate_row(d, copy_doc);
}
d.__unedited = true;
this.frm.script_manager.trigger(this.df.fieldname + "_add", d.doctype, d.name);
this.refresh();
} else {
Expand Down
18 changes: 18 additions & 0 deletions frappe/public/js/frappe/form/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ frappe.ui.form.save = function (frm, action, callback, btn) {
var freeze_message = working_label ? __(working_label) : "";

var save = function () {
remove_empty_rows();
$(frm.wrapper).addClass("validated-form");
if ((action !== "Save" || frm.is_dirty()) && check_mandatory()) {
_call({
Expand All @@ -38,6 +39,23 @@ frappe.ui.form.save = function (frm, action, callback, btn) {
}
};

var remove_empty_rows = function () {
const docs = frappe.model.get_all_docs(frm.doc);
const tables = docs.filter((d) => {
return frappe.model.is_table(d.doctype);
});
let modified_table_fields = [];
tables.forEach((doc) => {
if (locals[doc.doctype][doc.name].__unedited) {
frappe.model.clear_doc(doc.doctype, doc.name);
modified_table_fields.push(doc.parentfield);
}
});
modified_table_fields.forEach((field) => {
frm.refresh_field(field);
});
};

var cancel = function () {
var args = {
doctype: frm.doc.doctype,
Expand Down
1 change: 1 addition & 0 deletions frappe/public/js/frappe/model/create_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ $.extend(frappe.model, {

var child = frappe.model.get_new_doc(doctype, parent_doc, parentfield);
child.idx = idx;
child.__unedited = true;

// renum for fraction
if (idx !== cint(idx)) {
Expand Down