您可以通过 扩展 tailor 构建自定义内容字段。
内容字段是 Tailor 模块的基石,它定义了字段应如何配置和显示。这些定义通常可以在蓝图的 fields 属性下找到。
fields:
name:
label: Full Name
type: text可用字段的完整列表可在后端元素部分中找到。
对于每个字段,您都可以指定这些通用属性,在适用的情况下。
| Property | Description |
|---|---|
| label | a name when displaying the form field to the user. |
| shortLabel | a shorter label to use in lists and filters. |
| type | defines how this field should be rendered, see form field definitions. Default: text. |
| span | aligns the form field to one side. Options: auto, left, right, row, full, adaptive. Default: full. |
| spanClass | used with the span row option to display the form as a Bootstrap grid, for example, spanClass: col-4. |
| size | specifies a field size for fields that use it, for example, the textarea field. |
| placeholder | if the field supports a placeholder value. |
| comment | places a descriptive comment below the field. |
| commentAbove | places a comment above the field. |
| commentHtml | allow HTML markup inside the comment. Default: false. |
| default | specify the default value for the field. For dropdown, checkboxlist, radio and balloon-selector widgets, you may specify an option key here to have it selected by default. |
| tab | assigns the field to a tab. |
| validation | defines validation rules for the form field, see the validation article for rule definitions. |
| trigger | specify conditions for this field using trigger events. |
| preset | allows the field value to be initially set by the value of another field, converted using the input preset converter. |
| translatable | disables translation for this field when using the multisite in the blueprint definition. |
关于在列表或筛选器中显示字段,每个字段都有其默认设置。您可以按字段覆盖这些设置,这适用于微小调整。对于更复杂的用例,我们建议将列和范围与字段分开定义(见下文)。
| Property | Description |
|---|---|
| column | defines how to display the field in a list, see list column definitions. |
| scope | defines how to display the field in a filter, see filter scope definitions. |
一个例子可以是,通过使用字段的 column 或 scope 属性,为每个指定不同的标签。
myfield:
label: Form Label
column:
label: List Label
scope:
label: Filter Label如果 设置为 false,那么该字段将被禁用并阻止其显示。
myfield:
label: Form Label
column: false
scope: falsecolumn 类型可设置为 invisible,使其默认在列表中隐藏。
myfield:
label: Form Label
column: invisible你可以通过在蓝图中使用 columns 和 scopes 属性,独立于表单字段定义范围和列。当使用外部配置时,默认视图将仅由已定义的字段替换。
scopes:
myfield:
label: Filter Label
# [...]
columns:
myfield:
label: List Label
# [...]
fields:
myfield:
label: Form Label
# [...]一个 fields 定义必须存在,才能使一个 columns 或 scopes 定义有效。要在表单中隐藏该定义,请使用
hidden: true将其从表单中隐藏,然后使用hidden: false在列或范围中显示它。
列表列具有可用的速记值. 传递一个字符串将替换标签, 传递 true 将包含默认列, 传递 false 将删除该列和传递 invisible 将使该列不可见.
columns:
myfield: List Label # New Label
myfield: true # Shown
myfield: false # Hidden
myfield: invisible # Invisible
myfield: [...] # Config Array筛选器作用域具有与可用的列表列相似的简写值。
scopes:
myfield: Filter Label # New Label
myfield: true # Shown
myfield: false # Hidden
myfield: [...] # Config Array您可以使用 validation 字段属性为表单字段指定验证规则, 请参阅 验证文章 以了解规则定义.
fields:
myfield:
label: Featured Text
validation: "required|min:15"验证规则也可以在蓝图文件中外部定义,使用 validation 蓝图属性。这允许你设置自定义属性名称和验证消息。
validation:
rules:
myfield: "required|min:15"
attributeNames:
myfield: My Field
customMessages:
myfield.min: "My field has to be at least 15 characters long"
fields:
myfield:
label: Form Label
# [...]该 unique 验证规则已自动配置,并且不需要指定表名。
unique_field:
label: Unique Field
validation: uniquerequired 验证规则支持 create 和 update 修饰符,使其仅在模型分别被创建或更新时应用。以下内容仅在模型尚不存在时才需要。
password:
label: Password
validation: "required:create"每个蓝图记录具有若干核心字段,正如由模型上的属性定义。您可以在某些条件下修改这些字段。
条目默认情况下是启用的;但是,你可以通过为 is_enabled 字段指定新的默认值来修改这一点。
fields:
is_enabled:
default: falsetitle 字段占位符是基于蓝图名称生成的;但是,你可以根据用例将其自定义为更有用的内容。例如,名字和姓氏、活动标题或地点名称。
fields:
title:
placeholder: Event Title在某些情况下,title 字段可能不是必需的,例如使用 单个蓝图,您可以将 hidden 属性设置为 true。隐藏标题将禁用此字段的内置验证。
fields:
title:
hidden: true