无法限制 TagInputField 中的标签数量

Trouble limiting the number of tags in a TagInputField

根据 the documentation of the TagInputField widget,应该可以限制允许用户从 AEM 标签中的每个命名空间使用的标签数量。

namespaces : Array

A list of the tag namespaces that should be displayed and allowed. If empty, all available namespaces will be allowed. Otherwise either an array of Strings (the namespace names) or for more configuration an array of objects as this:

{
    name: "namespace",
    maximum: 1 // maximum number of tags allowed from this namespace; if -1 no limit (default)
}

但是当我尝试这样做时它似乎不起作用。

在我的场景中,我想将用户限制在一个名称空间内,并且只允许 her/him 选择一个标签。

当我只在 dialog.xml 中指定命名空间时,namespaces 设置得到尊重:

<tags
  jcr:primaryType="cq:Widget"
  allowBlank="true"
  fieldLabel="Tags"
  namespaces="[topics]"
  name="./tags"
  xtype="tags"/>

小部件仅显示来自 my-namespace

的标签

当我尝试限制来自该命名空间的标签数量时,问题就来了。

<tags
  jcr:primaryType="cq:Widget"
  allowBlank="true"
  fieldLabel="Tags"
  namespaces="[{name: &quot;topics&quot;, maximum: 1}]"
  name="./tags"
  xtype="tags"/>

这只是被忽略了,在使用保管库将内容导入 AEM 后似乎出现了问题。当我在 CRXDE 中检查它时,它看起来像一个具有两个值的字符串数组。

对话框的行为似乎证实它不仅仅是它在 CRXDE 中的显示方式的问题,因为小部件没有显示名称空间。

即使我在 CRXDE 中手动编辑字符串数组以获得正确的值(见下面的屏幕截图),对话框也不会选择任何名称空间(与上面相同)

有没有人以上述方式幸运地使用过这个小部件?我做错了什么还是这是一个错误?

我的同事刚刚回复了我一个答案。事实证明我误解了文档。配置(如果以复杂格式使用)实际上需要 JCR 节点的嵌套结构。

因此,在我的 dialog.xml 中,我需要一个额外的节点:

<tags
  jcr:primaryType="cq:Widget"
  allowBlank="true"
  fieldLabel="Tags"
  name="./tags"
  xtype="tags">
    <namespaces jcr:primaryType="cq:WidgetCollection">
        <topics jcr:primaryType="nt:unstructured" maximum="1" name="topics" />
    </namespaces>
</tags>

<tags
  jcr:primaryType="cq:Widget"
  fieldLabel="Tags"
  name="./tags"
  xtype="tags">

    <namespaces jcr:primaryType="cq:WidgetCollection">
        <topic1 jcr:primaryType="nt:unstructured" maximum="3" name="topic1" />
        <topic2 jcr:primaryType="nt:unstructured" maximum="3" name="topic2" />

    </namespaces>
</tags>

Link: - http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__5hd0-hi_all_in_ourco.html

也看看这个旧的post:- https://forums.adobe.com/thread/1175413

//

<locationTag jcr:primaryType="cq:Widget" allowBlank="{Boolean}false"  
       cls="cq-propsdialog-tags" fieldLabel="Campus Location"  
       fieldDescription="Specify a campus location" name="./locationID/cq:tags"  
                                                  xtype="tags">  
       <namespaces jcr:primaryType="cq:WidgetCollection">  
            <ns1 jcr:primaryType="nt:unstructured" maximum="1"  name="campuses" />  
       </namespaces>  
  </locationTag>  

希望对您有所帮助。

感谢和问候 考图克萨尼