You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法为page_excerpt的teaserImage设置mandatory=true的问题排查

问题原因及解决方案

问题出在你错误地在表单定义(page_excerpt.xml)中直接给系统 excerpt 字段添加 mandatory="true"。Sulu 中 excerpt 字段的必填规则不能通过表单属性直接设置,需要在页面模板的 excerpt 配置里定义验证规则。

正确的配置步骤:

  • 找到你的页面模板文件(通常位于 config/templates/pages/ 目录下,比如 page.xml)
  • 在模板的 <excerpt> 节点中,给 teaserImage 字段添加 required="true" 属性,示例如下:
<template xmlns="http://schemas.sulu.io/template/template"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.0.xsd">

    <!-- 其他模板配置... -->

    <excerpt>
        <properties>
            <property name="teaserImage" required="true"/>
        </properties>
    </excerpt>
</template>
  • 保留 page_excerpt.xml 中的字段定义,但移除 mandatory="true",保持原有结构即可:
<property name="ext/excerpt/teaserImage" type="single_media_selection">
    <meta>
        <title lang="en">Image</title>
    </meta>
</property>

为什么原来的方式不行?

Sulu 的表单定义文件(page_excerpt.xml)主要负责渲染表单的UI结构,而字段的必填验证规则属于内容类型的约束,需要在页面模板的 excerpt 配置中声明。直接在表单属性中添加 mandatory 会导致系统验证逻辑冲突,因为 excerpt 字段的验证由模板配置控制,而非表单渲染定义。

内容的提问来源于stack exchange,提问作者MadCatERZ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 11:01:19