@@ -14,7 +14,7 @@ import os, sys, importlib, inspect, json | |||||
from .exceptions import * | from .exceptions import * | ||||
from .utils.jinja import get_jenv, get_template, render_template, get_email_from_template | from .utils.jinja import get_jenv, get_template, render_template, get_email_from_template | ||||
__version__ = '8.7.3' | |||||
__version__ = '8.7.4' | |||||
__title__ = "Frappe Framework" | __title__ = "Frappe Framework" | ||||
local = Local() | local = Local() | ||||
@@ -512,14 +512,20 @@ def validate_fields(meta): | |||||
else: | else: | ||||
frappe.throw(_("Fold can not be at the end of the form")) | frappe.throw(_("Fold can not be at the end of the form")) | ||||
def check_search_fields(meta): | |||||
def check_search_fields(meta, fields): | |||||
"""Throw exception if `search_fields` don't contain valid fields.""" | """Throw exception if `search_fields` don't contain valid fields.""" | ||||
if not meta.search_fields: | if not meta.search_fields: | ||||
return | return | ||||
for fieldname in (meta.search_fields or "").split(","): | |||||
# No value fields should not be included in search field | |||||
search_fields = [field.strip() for field in (meta.search_fields or "").split(",")] | |||||
fieldtype_mapper = { field.fieldname: field.fieldtype \ | |||||
for field in filter(lambda field: field.fieldname in search_fields, fields) } | |||||
for fieldname in search_fields: | |||||
fieldname = fieldname.strip() | fieldname = fieldname.strip() | ||||
if fieldname not in fieldname_list: | |||||
if (fieldtype_mapper.get(fieldname) in no_value_fields) or \ | |||||
(fieldname not in fieldname_list): | |||||
frappe.throw(_("Search field {0} is not valid").format(fieldname)) | frappe.throw(_("Search field {0} is not valid").format(fieldname)) | ||||
def check_title_field(meta): | def check_title_field(meta): | ||||
@@ -616,7 +622,7 @@ def validate_fields(meta): | |||||
check_unique_and_text(d) | check_unique_and_text(d) | ||||
check_fold(fields) | check_fold(fields) | ||||
check_search_fields(meta) | |||||
check_search_fields(meta, fields) | |||||
check_title_field(meta) | check_title_field(meta) | ||||
check_timeline_field(meta) | check_timeline_field(meta) | ||||
check_is_published_field(meta) | check_is_published_field(meta) | ||||
@@ -54,3 +54,21 @@ class TestDocType(unittest.TestCase): | |||||
doc2.insert() | doc2.insert() | ||||
doc1.delete() | doc1.delete() | ||||
doc2.delete() | doc2.delete() | ||||
def test_validate_search_fields(self): | |||||
doc = self.new_doctype("Test Search Fields") | |||||
doc.search_fields = "some_fieldname" | |||||
doc.insert() | |||||
self.assertEqual(doc.name, "Test Search Fields") | |||||
# check if invalid fieldname is allowed or not | |||||
doc.search_fields = "some_fieldname_1" | |||||
self.assertRaises(frappe.ValidationError, doc.save) | |||||
# check if no value fields are allowed in search fields | |||||
field = doc.append("fields", {}) | |||||
field.fieldname = "some_html_field" | |||||
field.fieldtype = "HTML" | |||||
field.label = "Some HTML Field" | |||||
doc.search_fields = "some_fieldname,some_html_field" | |||||
self.assertRaises(frappe.ValidationError, doc.save) |
@@ -248,7 +248,7 @@ frappe.ui.Page = Class.extend({ | |||||
$group = $('<div class="btn-group" data-label="'+label+'" style="margin-left: 10px;">\ | $group = $('<div class="btn-group" data-label="'+label+'" style="margin-left: 10px;">\ | ||||
<button type="button" class="btn btn-default dropdown-toggle btn-xs" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\ | <button type="button" class="btn btn-default dropdown-toggle btn-xs" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\ | ||||
'+label+' <span class="caret"></span></button>\ | '+label+' <span class="caret"></span></button>\ | ||||
<ul class="dropdown-menu" style="margin-top: -8px;"></ul></div>').appendTo(this.inner_toolbar.removeClass("hide")); | |||||
<ul class="dropdown-menu" style="margin-top: -8px;"></ul></div>').appendTo(this.inner_toolbar); | |||||
} | } | ||||
return $group; | return $group; | ||||
}, | }, | ||||
@@ -280,6 +280,7 @@ frappe.ui.Page = Class.extend({ | |||||
}; | }; | ||||
if(group) { | if(group) { | ||||
var $group = this.get_inner_group_button(group); | var $group = this.get_inner_group_button(group); | ||||
$(this.inner_toolbar).removeClass("hide"); | |||||
return $('<li><a>'+label+'</a></li>') | return $('<li><a>'+label+'</a></li>') | ||||
.on('click', _action) | .on('click', _action) | ||||
.appendTo($group.find(".dropdown-menu")); | .appendTo($group.find(".dropdown-menu")); | ||||