【问题标题】:How to create a radio button in aem 6 touch dialog如何在 aem 6 触摸对话框中创建单选按钮
【发布时间】:2015-02-15 16:38:51
【问题描述】:

我有一个触摸 UI 组件,我正在 AEM 6 中为其创建一个对话框。我需要在触摸对话框中创建 2 个单选按钮,如果选择其中一个,则所选单选的相应值按钮应显示。但是,我不明白如何创建单选按钮选项。我在使用 xtype=selection 和 type=radiogroup 的经典对话框中实现了相同的功能,但我不明白如何在触摸对话框中创建它

【问题讨论】:

  • 我认为它与经典 ui 中的不同。你可能看过 /libs/foundation/components/form/radio 组件

标签: dialog aem sightly htl


【解决方案1】:

这是 CoralUI v1/v2 的无线电组示例。 radiogroup 是可选的,radio 小部件本身仍然可以工作。仅当您想为组添加标签时才需要该组。

<radioGroup jcr:primaryType="nt:unstructured"
    name="./type"
    text="Fruit"
    required="{Boolean}true"
    sling:resourceType="granite/ui/components/foundation/form/radiogroup"
    renderReadOnly="{Boolean}true">

    <items jcr:primaryType="nt:unstructured">
        <radioApple jcr:primaryType="nt:unstructured"
            name="./fruit"
            text="Apple"
            value="apple"
            cq-msm-lockable="fruit"
            sling:resourceType="granite/ui/components/foundation/form/radio"
            renderReadOnly="{Boolean}true"/>
        <radioPear jcr:primaryType="nt:unstructured"
            name="./fruit"
            text="Pear"
            value="pear"
            cq-msm-lockable="fruit"
            sling:resourceType="granite/ui/components/foundation/form/radio"
            renderReadOnly="{Boolean}true"/>
        <radioDefaultValue jcr:primaryType="nt:unstructured"
            name="./fruit@DefaultValue"
            value="apple"
            sling:resourceType="granite/ui/components/foundation/form/hidden"/>
        <radioDefaultWhenMissing jcr:primaryType="nt:unstructured"
            name="./fruit@UseDefaultWhenMissing"
            value="true"
            sling:resourceType="granite/ui/components/foundation/form/hidden"/>
    </items>
</radioGroup>

注意:如果您需要在打开对话框之前设置默认值,那么您需要在模板中定义它(如果是页面对话框)或为组件。

对于一个组件,要将默认值设置为apple,您可以将其添加到.content.xml

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0"
          xmlns:jcr="http://www.jcp.org/jcr/1.0"
          jcr:primaryType="cq:Component"
          jcr:title="Fruit Component"
          componentGroup="My App Group"
          sling:resourceSuperType="foundation/components/parbase">

    <cq:template jcr:primaryType="nt:unstructured" fruit="apple"/>
</jcr:root>

另见:

注意:

如果您正在为 AEM 6.3 进行开发,那么您将需要 所有组件的 CoralUI3 风格,即您应该使用 granite/ui/components/foundation/form/radio 而不是 granite/ui/components/coral/foundation/form/radio 等。

有关迁移到 CoralUI 3 的详细信息,请参阅https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/legacy/coral2/migration.html

【讨论】:

    【解决方案2】:

    您可以使用 Form Input - Radio 。要创建单选按钮组,请为所有单选按钮同名。 Radio输入的resourceType为/libs/granite/ui/components/foundation/form/radio

    节点的 Json 示例:

    "hideinnav": {
    "jcr:primaryType": "nt:unstructured",
    "name": "./hideInNav",
    "text": "Hide in Navigation",
    "value": "true",
    "cq-msm-lockable": "hideInNav",
    "sling:resourceType": "/libs/granite/ui/components/foundation/form/radio",
    "renderReadOnly": true
    },
    "showinNav": {
    "jcr:primaryType": "nt:unstructured",
    "name": "./hideInNav",
    "text": "Show in Navigation",
    "value": "false",
    "cq-msm-lockable": "hideInNav",
    "sling:resourceType": "/libs/granite/ui/components/foundation/form/radio",
    "renderReadOnly": true
    }
    

    与在选项节点下设置按钮的经典 UI 选择小部件不同,单选按钮是独立的,可以直接在容器中使用。

    【讨论】:

    • 感谢您的回答。但是,仍然存在 2 个小问题。第一个是,我无法在“触摸”对话框中为该单选组提供字段标签。如何做呢?这是必要的,因为作者应该知道他选择真/假单选选项是为了什么。第二个是,作者在下次打开触摸作者对话框时所做的选择不会以选中单选按钮的形式保存。这不是经典对话框的情况,一旦进行选择,作者的选择将以选中单选按钮的形式持续存在。我在这里遗漏了什么吗?
    • 你能分享你节点的xml或json吗
    • Sharath,我已将节点属性的屏幕截图附加到问题中。请参考它我不能尝试像在经典 UI 中那样添加 fieldLabel 属性,因为在那里,我们将它添加到 radiogroup 节点并在选项节点下提供选项,bur 在这里,每个选项都是一个单独的节点,带有 sling:resourceType 作为无线电。如何将它们分组?并且坚持用户选择,我在文档中看不到任何可以实现它的属性。如果您能提供帮助,请告诉我。
    • 文本选项旨在用作标签,因此它没有 fieldLabel。如果您仍然想要一个共同的标题,您可以将单选按钮放在字段集中并给字段集一个标题。未读回的值很奇怪,现在检查一下。不知道为什么硬。找不到任何带有单选按钮的 OOTB 组件。
    【解决方案3】:

    Coral UI3 不再支持单独的表单/收音机。这现在被表单/无线电组取代 https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/legacy/coral2/migration.html

    在 Coral UI3 中,要创建两个单选按钮,您可以执行以下操作:

       <radioGroup 
                jcr:primaryType="nt:unstructured"
                name=“./state“
                text=“Select an Option”
                sling:resourceType="granite/ui/components/coral/foundation/form/radiogroup">
                <items jcr:primaryType="nt:unstructured">
                    <radioExpanded jcr:primaryType="nt:unstructured"
                        text="Expanded"
                        value="expanded”/>  
                    <radioCollapse
                        jcr:primaryType="nt:unstructured"
                        text=“Collapse”
                        value=“collapse”/>
                </items>
            </radioGroup>
    

    【讨论】:

      【解决方案4】:

      AEM 6 Touch UI 不支持单选按钮组。相反,您可以使用下拉菜单? 吊索:resourceType="granite/ui/components/foundation/form/dropdown"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-07
        • 1970-01-01
        • 1970-01-01
        • 2012-03-14
        • 1970-01-01
        相关资源
        最近更新 更多