How to create a radio button in aem 6 touch dialog

夙愿已清 提交于 2019-12-04 14:07:43

You can use Form Input - Radio . To create a radio button group give all radio buttons the same name. The resourceType of Radio input is /libs/granite/ui/components/foundation/form/radio.

Sample Json of the Nodes :

"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
}

Unlike the Classic UI Selection widget where the buttons are set under options node , radio buttons are independent and can be directly used in containers.

Here is a radio group example for CoralUI v1/v2. The radiogroup is optional, the radio widgets on their own will still work. The group is only needed if you want to have a label for the group.

<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>

NOTE: If you need a default value to be set before you even open the dialog, then you'll need to define it in the template (if it is a page dialog) or for the component.

For a component, to set the default value to apple you would add this in the .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>

See also:

NOTE:

If you are developing for AEM 6.3 then you will want the CoralUI3 flavour of all the components, i.e. instead of granite/ui/components/foundation/form/radio you should use granite/ui/components/coral/foundation/form/radio, etc.

For details on migrating to CoralUI 3 see 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.

Radio button group is not supported in AEM 6 Touch UI. Instead, you could use a dropdown? sling:resourceType="granite/ui/components/foundation/form/dropdown"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!