复选框值仍然存在

时间:2014-08-29 18:59:00

标签: cq5 aem

我的对话框中有3个复选框小部件。并且在没有选择代码的情况下执行逻辑,问题是当我勾选option1 option2时,然后他们在内容节点中将它们的值设置为" ON"。但是如果我编辑相同的组件option1,则选择option2,我取消选择一个并单击ok,仍然在内容节点属性中存在值为" ON"。

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="cq:Dialog"
    title="dialog"
    xtype="dialog">
    <items
        jcr:primaryType="cq:Widget"
        xtype="tabpanel">
        <items jcr:primaryType="cq:WidgetCollection">
            <tab1
                jcr:primaryType="cq:Panel"
                title="Select Options">
                <items jcr:primaryType="cq:WidgetCollection">
                    <facebook
                        jcr:primaryType="cq:Widget"
                        fieldLabel="Facebook"
                        name="./facebook"
                        xtype="checkbox"/>
                    <twitter
                        jcr:primaryType="cq:Widget"
                        fieldLabel="Twitter"
                        name="./twitter"
                        xtype="checkbox"/>
                    <linkedin
                        jcr:primaryType="cq:Widget"
                        fieldLabel="Linkedin"
                        name="./linkedin"
                        xtype="checkbox"/>
                </items>
            </tab1>
        </items>
    </items>
</jcr:root>

2 个答案:

答案 0 :(得分:6)

checkbox xtype我没有取得多大成功。相反,请尝试selection xtype,其类型为checkbox

<facebook
    jcr:primaryType="cq:Widget"
    fieldLabel="Facebook"
    name="./facebook"
    type="checkbox"
    xtype="selection"/>

答案 1 :(得分:4)

您遇到的问题是,当您取消选中该复选框时,表单根本就不会将该字段发送到POST中,因此Sling根本不会修改该属性。

为了能够保持未选中状态,您需要添加默认值。您可以使用Sling Suffixes执行此操作。

  • parameter@Delete,如果没有发送其他值,则会从jcr中删除属性。在你的情况下,你可以解释没有属性为未选中
  • parameter@DefaultValue可用于在没有任何值的情况下发送参数的情况下发送默认值
  • parameter@UseDefaultWhenMissing = true,可用于强制Sling在未发送参数时使用默认值。

因此,在您的特定情况下,添加具有以下名称的隐藏字段(xtype:hidden)&amp;值。

  1. ./facebook@DefaultValue="off"
  2. ./facebook@UseDefaultWhenMissing="true"
  3. 这将确保价值&#34;关闭&#34;在未选中复选框时使用。

    ps-是的,在AEM / CQ

    中使用复选框很烦人