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: Web form child table new rows save #203

Closed
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
13 changes: 11 additions & 2 deletions frappe/public/js/frappe/form/grid.js
Expand Up @@ -193,6 +193,10 @@ export default class Grid {
}
}
refresh(force) {
if (!this.df.data){this.df.data = [];}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!this.df.data){this.df.data = [];}
this.df.data = this.df.data || [];


this.data = this.get_data();

!this.wrapper && this.make();
var me = this,
$rows = $(me.parent).find(".rows"),
Expand Down Expand Up @@ -365,6 +369,7 @@ export default class Grid {
$(this.frm.wrapper).trigger("grid-make-sortable", [this.frm]);
}
get_data() {
// this.remove_all();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

var data = this.frm ?
this.frm.doc[this.df.fieldname] || []
: this.df.data || this.get_modal_data();
Expand Down Expand Up @@ -489,7 +494,12 @@ export default class Grid {
if (!this.df.data) {
this.df.data = this.get_data() || [];
}
this.df.data.push({idx: this.df.data.length+1, __islocal: true});
var d = { idx: this.df.data.length + 1, __islocal: true, doctype: this.doctype, parentfield: this.df.fieldname, parenttype: frappe.web_form.doctype }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Break this into multiple lines
  • Use const instead of var
  • Change the variable to row

this.df.data.push(d);
if(!frappe.web_form.doc.hasOwnProperty(this.df.fieldname)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just use the in operator to do this check:

Suggested change
if(!frappe.web_form.doc.hasOwnProperty(this.df.fieldname)) {
if (!(this.df.fieldname in frappe.web_form.doc)) {

frappe.web_form.doc[this.df.fieldname] = [];
}
frappe.web_form.doc[this.df.fieldname].push(d);
this.refresh();
}

Expand All @@ -506,7 +516,6 @@ export default class Grid {
}
}
}

return d;
}
}
Expand Down