From 4ca530aa31503f3387e77f09e9ad14e17ca2e033 Mon Sep 17 00:00:00 2001 From: MaxMorais Date: Fri, 24 Jul 2015 20:01:43 +0000 Subject: [PATCH 1/3] This small fix, ensure that the default value to the Select field, is a string. We can pass options hardcoded has {'key': 'the_key', 'label': 'The Label'}, but the code crash. This fix ensure that the code dont will broken in these cases. When it is utils? - Small customizations requires personalize in a specific context the value of select fields, like "Person Type" in "Customer", whithout crash the standard behavior of the field, and add more options. --- frappe/public/js/frappe/model/create_new.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/public/js/frappe/model/create_new.js b/frappe/public/js/frappe/model/create_new.js index aada2e3982..72f206b541 100644 --- a/frappe/public/js/frappe/model/create_new.js +++ b/frappe/public/js/frappe/model/create_new.js @@ -65,7 +65,7 @@ $.extend(frappe.model, { doc[f.fieldname] = v; updated.push(f.fieldname); - } else if(f.fieldtype == "Select" && f.options + } else if(f.fieldtype == "Select" && f.options && typeof f.options === 'string' && !in_list(["[Select]", "Loading..."], f.options)) { doc[f.fieldname] = f.options.split("\n")[0]; } @@ -278,4 +278,4 @@ $.extend(frappe.model, { _map(); } } -}) +}) \ No newline at end of file From 7e8fbb3a25c4c3d20279c08143a785e6d1fc024b Mon Sep 17 00:00:00 2001 From: MaxMorais Date: Fri, 24 Jul 2015 20:05:46 +0000 Subject: [PATCH 2/3] This fix ensure that the syntax: `refresh_field("my_field", [null [child name]], table_field)` Already will refresh the field in a grid row. --- frappe/public/js/legacy/clientscriptAPI.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/frappe/public/js/legacy/clientscriptAPI.js b/frappe/public/js/legacy/clientscriptAPI.js index a34bccab58..5c5e3ed1cc 100644 --- a/frappe/public/js/legacy/clientscriptAPI.js +++ b/frappe/public/js/legacy/clientscriptAPI.js @@ -66,8 +66,19 @@ refresh_field = function(n, docname, table_field) { if(typeof n==typeof []) refresh_many(n, docname, table_field); - if(table_field && cur_frm.fields_dict[table_field].grid.grid_rows_by_docname) { // for table - cur_frm.fields_dict[table_field].grid.grid_rows_by_docname[docname].refresh_field(n); + if (n && typeof n==='string' && table_field){ + var grid = cur_frm.fields_dict[table_field].grid, + field = frappe.utils.filter_dict(grid.docfields, {fieldname: n}); + if (field && field.length){ + field = field[0]; + var meta = frappe.meta.get_docfield(field.parent, field.fieldname, docname); + $.extend(field, meta); + if (docname){ + cur_frm.fields_dict[table_field].grid.grid_rows_by_docname[docname].refresh_field(n); + } else { + cur_frm.fields_dict[table_field].grid.refresh(); + } + } } else if(cur_frm) { cur_frm.refresh_field(n) } @@ -158,11 +169,11 @@ _f.Frm.prototype.get_docfield = function(fieldname1, fieldname2) { } } -_f.Frm.prototype.set_df_property = function(fieldname, property, value) { +_f.Frm.prototype.set_df_property = function(fieldname, property, value, table_field) { var field = this.get_docfield(fieldname); if(field) { field[property] = value; - this.refresh_field(fieldname); + refresh_field(fieldname, table_field); }; } From 0f4abc3e4ad3cd3957f9b445aaaf74cd42022bcb Mon Sep 17 00:00:00 2001 From: MaxMorais Date: Fri, 24 Jul 2015 20:15:54 +0000 Subject: [PATCH 3/3] This commit fix the hability of set a property for a item in the grid --- frappe/public/js/legacy/clientscriptAPI.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/frappe/public/js/legacy/clientscriptAPI.js b/frappe/public/js/legacy/clientscriptAPI.js index 5c5e3ed1cc..39b5a5841e 100644 --- a/frappe/public/js/legacy/clientscriptAPI.js +++ b/frappe/public/js/legacy/clientscriptAPI.js @@ -169,8 +169,15 @@ _f.Frm.prototype.get_docfield = function(fieldname1, fieldname2) { } } -_f.Frm.prototype.set_df_property = function(fieldname, property, value, table_field) { - var field = this.get_docfield(fieldname); +_f.Frm.prototype.set_df_property = function(fieldname, property, value, docname, table_field) { + if (!docname && !table_field){ + var field = this.get_docfield(fieldname); + } else { + var grid = cur_frm.fields_dict[table_field].grid, + fname = frappe.utils.filter_dict(grid.docfields, {'fieldname': fieldname}); + if (fname && fname.length) + var field = frappe.meta.get_docfield(fname[0].parent, fieldname, docname); + } if(field) { field[property] = value; refresh_field(fieldname, table_field);