fix: handle non-configured fields

This commit is contained in:
Rucha Mahabal 2020-11-30 14:12:48 +05:30
parent 5e3c51bf7d
commit 4ee293d2f4
3 changed files with 14 additions and 8 deletions

View File

@ -22,7 +22,8 @@
{
"fieldname": "selected_fields",
"fieldtype": "Code",
"label": "selected_fields"
"label": "Selected Fields",
"read_only": 1
},
{
"fieldname": "add_edit_fields",
@ -41,7 +42,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2020-11-28 19:04:48.323164",
"modified": "2020-11-30 13:54:37.474671",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Patient History Custom Document Type",

View File

@ -14,7 +14,11 @@ frappe.ui.form.on('Patient History Settings', {
},
field_selector: function(frm, doc, standard=1) {
let document_fields = (JSON.parse(doc.selected_fields)).map(f => f.fieldname);
let document_fields = [];
if (doc.selected_fields)
document_fields = (JSON.parse(doc.selected_fields)).map(f => f.fieldname);
let doctype_fields = frm.events.get_doctype_fields(frm, doc.document_type, document_fields);
let d = new frappe.ui.Dialog({
title: __('{0} Fields', [__(doc.document_type)]),
fields: [
@ -22,7 +26,7 @@ frappe.ui.form.on('Patient History Settings', {
label: __('Select Fields'),
fieldtype: 'MultiCheck',
fieldname: 'fields',
options: frm.events.get_doctype_fields(frm, doc.document_type, document_fields),
options: doctype_fields,
columns: 2
}
]
@ -49,7 +53,7 @@ frappe.ui.form.on('Patient History Settings', {
if (standard)
doctype = 'Patient History Standard Document Type';
d.refresh();
frappe.model.set_value(doctype, doc.name, 'selected_fields', JSON.stringify(selected_fields));
d.hide();
});
@ -82,7 +86,7 @@ frappe.ui.form.on('Patient History Custom Document Type', {
add_edit_fields: function(frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (row.document_type) {
frm.events.field_selector(frm, row, standard=0);
frm.events.field_selector(frm, row, 0);
}
}
});

View File

@ -23,7 +23,8 @@
{
"fieldname": "selected_fields",
"fieldtype": "Code",
"label": "Selected Fields"
"label": "Selected Fields",
"read_only": 1
},
{
"fieldname": "add_edit_fields",
@ -43,7 +44,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2020-11-30 12:15:14.940935",
"modified": "2020-11-30 13:54:56.773325",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Patient History Standard Document Type",