【问题标题】:Allow blank value in AEM Touch UI multifield (select field)在 AEM Touch UI 多字段中允许空白值(选择字段)
【发布时间】:2014-10-30 22:54:28
【问题描述】:

我在组件对话框节点中创建了 AEM Touch UI multifield。它有一个select 的子字段。选择控件包含权限列表。这个想法是,作者可以选择多个权限,并且用户必须至少拥有其中一个权限才能看到组件,或者如果没有为该组件指定权限,所有用户都会看到它。下面是对话框选项卡的.content.xml 文件(该选项卡通过granite/ui/components/foundation/include 引用包含在内)。

我可以向多字段添加新权限、更改它们并删除它们,但需要注意的是:我无法删除列表中的最后一个权限。出于某种原因,一旦我选择了某些内容,AEM 就不允许我拥有一个空的多字段。我尝试将allowBlank 设置为true,但我认为此属性不适用于Touch UI——无论哪种方式,它都不能解决问题。

如何允许内容作者删除多字段中的所有项目?

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:primaryType="nt:unstructured"
    jcr:title="Portal Filters"
    sling:resourceType="granite/ui/components/foundation/container">
    <items jcr:primaryType="nt:unstructured">
        <permissions
            jcr:primaryType="nt:unstructured"
            sling:resourceType="granite/ui/components/foundation/form/multifield"
            fieldDescription="A user must have at least one of these permissions to view this component"
            fieldLabel="Permissions">
            <field
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/foundation/form/select"
                name="./permissions">
                <datasource
                    jcr:primaryType="nt:unstructured"
                    sling:resourceType="/apps/mportal/datasources/permissions"/>
            </field>
        </permissions>
        <missions
            jcr:primaryType="nt:unstructured"
            sling:resourceType="granite/ui/components/foundation/form/multifield"
            fieldDescription="A user must have at least one of these missions to view this component"
            fieldLabel="Missions">
            <field
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/foundation/form/select"
                name="./missions">
                <datasource
                    jcr:primaryType="nt:unstructured"
                    sling:resourceType="/apps/mportal/datasources/missions"/>
            </field>
        </missions>
        <mtcs
            jcr:primaryType="nt:unstructured"
            sling:resourceType="granite/ui/components/foundation/form/multifield"
            fieldDescription="A user must have at least one of these mtcs to view this component"
            fieldLabel="MTCs">
            <field
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/foundation/form/select"
                name="./mtcs">
                <datasource
                    jcr:primaryType="nt:unstructured"
                    sling:resourceType="/apps/mportal/datasources/mtcs"/>
            </field>
        </mtcs>
        <languages
            jcr:primaryType="nt:unstructured"
            sling:resourceType="granite/ui/components/foundation/form/multifield"
            fieldDescription="A user must have at least one of these languages to view this component"
            fieldLabel="Languages">
            <field
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/foundation/form/select"
                name="./languages">
                <datasource
                    jcr:primaryType="nt:unstructured"
                    sling:resourceType="/apps/mportal/datasources/languages"/>
            </field>
        </languages>
        <startdate
            jcr:primaryType="nt:unstructured"
            sling:resourceType="granite/ui/components/foundation/form/datepicker"
            fieldLabel="Start Date"
            name="./startdate"/>
        <enddate
            jcr:primaryType="nt:unstructured"
            sling:resourceType="granite/ui/components/foundation/form/datepicker"
            fieldLabel="End Date"
            name="./enddate"/>
    </items>
</jcr:root>

【问题讨论】:

    标签: aem


    【解决方案1】:

    事实证明,AEM Touch UI 多字段组件更新值的方式存在问题。如果您删除最后一项,该组件不会向服务器发送任何值(很像未选中的复选框)。如果其中没有项目,您必须明确告诉 AEM 您要删除多字段的值。方法如下:

    1. 在与多字段节点相同的级别,创建一个新节点 (nt:非结构化);我叫它permissions-delete(对应 我的多字段名为permissions)
    2. 添加以下属性:
      1. sling:resourceType, String, granite/ui/components/foundation/form/hidden
      2. nameString./permissions@Delete(其中./permissionspermissions/field 节点的名称字段的值)
      3. valueBoolean,是的

    现在,当您删除最后一项时,隐藏字段的值将确保它被删除而不是被忽略。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      • 1970-01-01
      • 2010-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多