@@ -0,0 +1,17 @@ | |||||
In case where a code and a name is maintained for an entity, (for example for Employee there may be an Employee Code and Employee Name) and we want to show both the ID and name in a link field, we can make a formatter. | |||||
#### Example: | |||||
frappe.form.link_formatters['Employee'] = function(value, doc) { | |||||
if(doc.employee_name && doc.employee_name !== value) { | |||||
return value + ': ' + doc.employee_name; | |||||
} else { | |||||
return value; | |||||
} | |||||
} | |||||
Notes: | |||||
1. Both the primary key (`name) and the descriptive name (e.g. `employee_name`) must be present in the document. The descriptive name field could be hidden | |||||
1. This needs to be loaded before the document is loaded and can be re-used for all forms. You can also add it in `build.json` | |||||
@@ -0,0 +1,5 @@ | |||||
# Desk Customization | |||||
Articles related to customization of Frappe Desk | |||||
{index} |
@@ -5,6 +5,8 @@ | |||||
frappe.provide("frappe.form.formatters"); | frappe.provide("frappe.form.formatters"); | ||||
frappe.form.link_formatters = {}; | |||||
frappe.form.formatters = { | frappe.form.formatters = { | ||||
_right: function(value, options) { | _right: function(value, options) { | ||||
if(options && options.inline) { | if(options && options.inline) { | ||||
@@ -60,11 +62,16 @@ frappe.form.formatters = { | |||||
return '<i class="icon-ban-circle text-extra-muted" style="margin-right: 3px;"></i>'; | return '<i class="icon-ban-circle text-extra-muted" style="margin-right: 3px;"></i>'; | ||||
} | } | ||||
}, | }, | ||||
Link: function(value, docfield, options) { | |||||
Link: function(value, docfield, options, doc) { | |||||
var doctype = docfield._options || docfield.options; | var doctype = docfield._options || docfield.options; | ||||
if(value && value.match(/^['"].*['"]$/)) { | if(value && value.match(/^['"].*['"]$/)) { | ||||
return value.replace(/^.(.*).$/, "$1"); | |||||
value.replace(/^.(.*).$/, "$1"); | |||||
} | |||||
if(frappe.form.link_formatters[doctype]) { | |||||
value = frappe.form.link_formatters[doctype](value, doc); | |||||
} | } | ||||
if(options && options.for_print) { | if(options && options.for_print) { | ||||
return value; | return value; | ||||
} | } | ||||
@@ -21,7 +21,7 @@ class BlogPost(WebsiteGenerator): | |||||
def make_route(self): | def make_route(self): | ||||
if not self.route: | if not self.route: | ||||
return 'blog/' + frappe.db.get_value('Blog Category', self.blog_category, | |||||
return frappe.db.get_value('Blog Category', self.blog_category, | |||||
'route') + '/' + self.scrub(self.title) | 'route') + '/' + self.scrub(self.title) | ||||
def get_feed(self): | def get_feed(self): | ||||