浏览代码

fix: has_content check for fieldtype TextEditor

When a TextEditor field contains only an image, while checking for
content, HTML tags are stripped off including the only image.
This change adds a loose but explicit check for img tag.

(cherry picked from commit d11692c52f)
version-14
Faris Ansari 2 年前
committed by Mergify
父节点
当前提交
bd69c67f42
共有 1 个文件被更改,包括 10 次插入1 次删除
  1. +10
    -1
      frappe/model/base_document.py

+ 10
- 1
frappe/model/base_document.py 查看文件

@@ -671,10 +671,19 @@ class BaseDocument:


return _("Error: Value missing for {0}: {1}").format(_(df.parent), _(df.label)) return _("Error: Value missing for {0}: {1}").format(_(df.parent), _(df.label))


def has_content(df):
value = cstr(self.get(df.fieldname))
has_text_content = strip_html(value).strip()
has_img_tag = "<img" in value
if df.fieldtype == "Text Editor" and (has_text_content or has_img_tag):
return True
else:
return has_text_content

missing = [] missing = []


for df in self.meta.get("fields", {"reqd": ("=", 1)}): for df in self.meta.get("fields", {"reqd": ("=", 1)}):
if self.get(df.fieldname) in (None, []) or not strip_html(cstr(self.get(df.fieldname))).strip():
if self.get(df.fieldname) in (None, []) or not has_content(df):
missing.append((df.fieldname, get_msg(df))) missing.append((df.fieldname, get_msg(df)))


# check for missing parent and parenttype # check for missing parent and parenttype


正在加载...
取消
保存