DocField 定义了 DocType 的一个属性(或字段)。你可以为 DocField 定义列名、标签、数据类型等。例如,一个待办事项(ToDo)文档类型具有字段 description、status 和 priority。这些字段最终会成为数据库表 tabToDo 中的列。
示例
DocField 存储有关该字段的元数据。下面描述了其中的一些。
[
{
"label": "Description", // the value shown to the user (Form, Print, etc)
"fieldname": "description", // the property name we refer in code, also the column name
"fieldtype": "Text Editor", // the fieldtype which also decides how to store this value
"reqd": 1 // whether this field is mandatory
},
{
"label": "Status",
"fieldname": "status",
"fieldtype": "Select",
"options": [
"Open",
"Pending",
"Closed"
]
},
{
"label": "Priority",
"fieldname": "priority",
"fieldtype": "Select",
"options": [ // list of options for select
"Low",
"Medium",
"High"
],
"default": "Low" // the default value to be set
},
{
"label": "Completed By",
"fieldname": "completed_by",
"fieldtype": "Link",
"options": "User",
"depends_on": "eval: doc.status == 'Closed'", // the condition on which this field's display depends
},
{
"collapsible": 1,
"collapsible_depends_on": "eval:doc.status!='Closed'", // determines if a Section Break field is collapsible
"fieldname": "sb_details",
"fieldtype": "Section Break",
"label": "Details"
},
{
"fieldname": "amount",
"fieldtype": "Currency", // Currency field
"label": "Amount",
"non_negative": 1, // determines whether this field value can be negative
"options": "INR",
}
]
类似于 depends_on 属性(该属性决定字段是否显示),
在版本 12 中,我们引入了两个新属性:
mandatory_depends_on:如果满足此条件,该字段将成为必填项。read_only_depends_on:如果满足此条件,该字段将变为只读。
Frappe 内置了超过 30 种不同的字段类型。
这些字段类型适用于各种使用场景。你可以在下一页了解更多关于字段类型的信息。