Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!

Nested Multifield is not working in aem 6.5

Avatar

Level 2

Hi,

I have created one header banner with button component here button is .hidden component so i can use when ever i required button component just i use it. however I am facing an issue 

nave_27_0-1658603081645.png

 

here we have button list if author in first multifield in item0 inside that button we have some drop down values if i select URL 

one URL path field will be visible and next authoring next multifield inside that we have again button multifield if author now anchor one anchor field will open but issue is that which i author in last anchor is author field is getting opened in first multifield.

 

(function(document, $) {
    "use strict";
    // when dialog gets injected
    $(document).on("foundation-contentloaded", function(e) {
        // if there is already an inital value make sure the according target element becomes visible
        showHideHandler($(".cq-dialog-dropdown-showhide-multi", e.target));
        showHideContHandler($(".cq-dialog-dropdown-height-selection", e.target));
    });

    function showHideContHandler(el) {
        el.each(function(i, element) {
            Coral.commons.ready(element, function(component) {
                showHideCont(component, element);
                component.on("change", function() {
                    showHideCont(component, element);
                });
            });
        })
    }

    $(document).on("selected", ".cq-dialog-dropdown-showhide-multi", function(e) {
        showHideHandler($(this));
    });

    $(document).on("click", "button[coral-multifield-add]", function(e) {
        showHideHandler($(".cq-dialog-dropdown-showhide-multi"));
        showHideContHandler($(".cq-dialog-dropdown-height-selection"));

    });

    function showHideHandler(el) {
        el.each(function(i, element) {
            if ($(element).is("coral-select")) {
                // handle Coral3 base drop-down
                Coral.commons.ready(element, function(component) {
                    showHide(component, element);
                    component.on("change", function() {
                        showHide(component, element);
                    });
                });
            } else {
                // handle Coral2 based drop-down
                var component = $(element).data("select");
                if (component) {
                    showHide(component, element);
                }
            }
        })
    }

    function showHide(component, element) {
        // get the selector to find the target elements. its stored as data-.. attribute
        //var target = $(element).data("cqDialogDropdownShowhideTarget");
        var target = $(element).data("cq-dialog-dropdown-showhide-target");
        var $target = $(target);
        var elementIndex = $(element).closest('coral-multifield-item').index();

        if (target) {
            var value;
            if (component.value) {
                value = component.value;
            } else {
                value = component.getValue();
            }


            $(element).closest('coral-multifield-item').find(target).each(function(index) {
                var tarIndex = $(this).closest('coral-multifield-item').index();
                if (elementIndex == tarIndex) {
                    $(this).not(".hide").addClass("hide");

                    $(this).filter(function() {
                        return $(this).closest('.showhidetargetmulti').data('showhidetargetmultivalue').replace(/ /g, '').split(',').includes(value);
                    }).removeClass("hide");

                    // $(this).filter("[data-showhidetargetmultivalue='" + value + "']").parent().removeClass("hide");
                }
            });

        }


    }

    function showHideCont(component, element) {
        // get the selector to find the target elements. its stored as data-.. attribute
        var target = $(element).data("cqDialogDropdownShowhideTarget");
        var $target = $(target);

        if (target) {
            var value;

            if (typeof component.value !== "undefined") {
                value = component.value;

            } else if (typeof component.getValue === "function") {
                value = component.getValue();
            }

            if (value === 'm-hbanner--small') {
                $target.each(function() {
                    $(this).not(".hide").addClass("hide");
                    var label = $(this).attr("aria-labelledby").split(" ")[0];
                    var desc = $(this).attr("aria-labelledby").split(" ")[1];
                    var labelEl = document.getElementById(label);
                    var descEl = document.querySelectorAll('[aria-describedby="' + desc + '"]');
                    $(labelEl).not(".hide").addClass("hide");
                    $(descEl).not(".hide").addClass("hide");
                });
            } else {
                $target.each(function() {
                    $(this).removeClass("hide");
                    var label = $(this).attr("aria-labelledby").split(" ")[0];
                    var desc = $(this).attr("aria-labelledby").split(" ")[1];
                    var labelEl = document.getElementById(label);
                    var descEl = document.querySelectorAll('[aria-describedby="' + desc + '"]');
                    $(labelEl).removeClass("hide");
                    $(descEl).removeClass("hide");

                });
            }
        }
    }



})(document, Granite.$);

 

 

Please can any help me. I am stuck on this.

 

@arunpatidar @Anudeep_Garnepudi  @kautuk_sahni 

1 Reply

Avatar

Level 2

Header Banner XML:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:cq="http://www.day.com/jcr/cq/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="Header Banner"
    sling:resourceType="cq/gui/components/authoring/dialog"
    extraClientlibs="[headerbanner.clientlibs,button.clientlibs]">
    <content
        granite:class="tabselection"
        jcr:primaryType="nt:unstructured"
        sling:resourceType="granite/ui/components/coral/foundation/container">
        <items jcr:primaryType="nt:unstructured">
            <tabs
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/coral/foundation/tabs"
                maximized="{Boolean}true">
                <items jcr:primaryType="nt:unstructured">
                    <styling
                        jcr:primaryType="nt:unstructured"
                        jcr:title="Banner Style"
                        sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"
                        margin="{Boolean}true">
                        <items jcr:primaryType="nt:unstructured">
                            <column
                                jcr:primaryType="nt:unstructured"
                                sling:resourceType="granite/ui/components/coral/foundation/container">
                                <items jcr:primaryType="nt:unstructured">
                                    <bannerHeight
                                        granite:class="cq-dialog-dropdown-height-selection"
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/select"
                                        fieldDescription="Small (264px), Medium (468px), Large (540px), or Custom (based on text height).  "
                                        fieldLabel="Banner Height"
                                        name="./bannerHeight"
                                        tooltipPosition="[bottom]"
                                        value="small_class">
                                        <items jcr:primaryType="nt:unstructured">
                                            <v1
                                                jcr:primaryType="nt:unstructured"
                                                text="Small"
                                                value="m-hbanner--small"/>
                                            <v2
                                                jcr:primaryType="nt:unstructured"
                                                text="Medium"
                                                 selected="{Boolean}true"
                                                value="m-hbanner--standard"/>
                                            <v3
                                                jcr:primaryType="nt:unstructured"
                                                text="Large"
                                                value="m-hbanner--campaign"/>
                                            <custom
                                                jcr:primaryType="nt:unstructured"
                                                text="Custom"
                                                value="m-hbanner--content-height"/>
                                        </items>
                                        <granite:data
                                            jcr:primaryType="nt:unstructured"
                                            cq-dialog-dropdown-showhide-target=".showhidecontainer"/>
                                    </bannerHeight>                            
                                    <backgroundType
                                        granite:class="dropdown-selection"
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/select"
                                        fieldDescription="Please choose the type of background "
                                        fieldLabel="Background Type"
                                        name="./backgroundType"
                                        value="solidcolor">
                                        <items jcr:primaryType="nt:unstructured">
                                            <solidColor
                                                jcr:primaryType="nt:unstructured"
                                                text="Solid Color"
                                                value="solidColor"/>
                                            <imageBackground
                                                jcr:primaryType="nt:unstructured"
                                                text="Image"
                                                value="imageBackground"/>
                                        </items>
                                    </backgroundType>
                                    <topMargin
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                        fieldDescription="Add Top margin of 48px for the component "
                                        fieldLabel="Top Margin"
                                        name="./topMargin"
                                        text="Top Margin"
                                        uncheckedValue="false"
                                        value="true"/>
                                    <bottomMargin
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                        fieldDescription="Add Bottom margin of 48px for the component "
                                        fieldLabel=" Bottom Margin"
                                        name="./bottomMargin"
                                        text="Bottom Margin"
                                        uncheckedValue="false"
                                        value="true"/>
                                    <hideMobile
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                        fieldLabel="Hide image on mobile"
                                        name="./hideMobile"
                                        text="Hide image on mobile"
                                        uncheckedValue="false"
                                        value="true"/>
                                </items>
                            </column>
                        </items>
                    </styling>
                    <imageTextTab
                        jcr:primaryType="nt:unstructured"
                        jcr:title="Banner Content"
                        sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"
                        margin="{Boolean}true">
                        <items jcr:primaryType="nt:unstructured">
                            <column
                                jcr:primaryType="nt:unstructured"
                                sling:resourceType="granite/ui/components/coral/foundation/container">
                                <items jcr:primaryType="nt:unstructured">
                                    <textContainerWidth
                                        granite:class="dropdown-selection"
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/select"
                                        fieldDescription="For use in customizing text container based on background image "
                                        fieldLabel="Text Container Width"
                                        name="./textContainerWidth"
                                        value="100%">
                                        <items jcr:primaryType="nt:unstructured">
                                            <v1
                                                jcr:primaryType="nt:unstructured"
                                                text="100%"
                                                value="m-hbanner__content--full"/>
                                            <v2
                                                jcr:primaryType="nt:unstructured"
                                                text="75%"
                                                value="m-hbanner__content--col9"/>
                                            <v3
                                                jcr:primaryType="nt:unstructured"
                                                text="66%"
                                                value="m-hbanner__content--col8"/>
                                            <v4
                                                jcr:primaryType="nt:unstructured"
                                                text="50%"
                                                value="m-hbanner__content--half"/>
                                        </items>
                                    </textContainerWidth>
                                    <stopCarouselAutoRotate
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                        fieldDescription="Allows user to click on banner to stop auto-rotate of carousel"
                                        fieldLabel="Enable User Click to Stop Carousel Auto-Rotate  "
                                        name="./stopCarouselAutoRotate"
                                        text="Enable User Click to Stop Carousel Auto-Rotate  "
                                        uncheckedValue="false"
                                        value="true"/>
                                    <imageTextItems
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
                                        composite="{Boolean}true"
                                        fieldDescription="Click on the + button to add Image and Text configs"
                                        fieldLabel="Image / Text"
                                        validation="imagetext-multifield-validate">
                                        <granite:data
                                            jcr:primaryType="nt:unstructured"
                                            componentname="headerBanner"
                                            maxlinksallowed="5"/>
                                        <field
                                            jcr:primaryType="nt:unstructured"
                                            sling:resourceType="granite/ui/components/coral/foundation/container"
                                            name="./imageTextList">
                                            <items jcr:primaryType="nt:unstructured">
                                                <backgroundImage
                                                    jcr:primaryType="nt:unstructured"
                                                    sling:resourceType="granite/ui/components/coral/foundation/form/pathfield"
                                                    fieldDescription="Small: 1440x264, Medium: 1440x448, Large: 1440x540, Custom: height based on text content. Image files should be 512KB maximum. "
                                                    fieldLabel="Background Image"
                                                    name="./imageFileReference"
                                                    rootPath="/content/dam"/>
                                                <decorative
                                                    granite:class="cq-dialog-checkbox-showhide-multifield"
                                                    jcr:primaryType="nt:unstructured"
                                                    sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                                    fieldDescription="Check if the image should be ignored by assistive technology and therefore does not require an alternative text. This applies to decorative images only."
                                                    name="./decorative"
                                                    text="Image is decorative"
                                                    uncheckedValue="false"
                                                    value="{Boolean}true">
                                                    <granite:data
                                                        jcr:primaryType="nt:unstructured"
                                                        cq-dialog-checkbox-showhide-target=".togglefield"/>
                                                </decorative>
                                                <container
                                                    granite:class="togglefield"
                                                    jcr:primaryType="nt:unstructured"
                                                    sling:orderBefore="id"
                                                    sling:resourceType="granite/ui/components/coral/foundation/container">
                                                    <items jcr:primaryType="nt:unstructured">
                                                         <altText
                                                                jcr:primaryType="nt:unstructured"
                                                                sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
                                                                fieldDescription="Please enter Alternate Text for Banner Image"
                                                                fieldLabel="Image Alternate Text"
                                                                name="./altText"/>                            
                                                    </items>
                                                    <granite:data jcr:primaryType="nt:unstructured"
                                                        showhidetargetvalue=""/>
                                                </container>       
                                                <title
                                                    jcr:primaryType="nt:unstructured"
                                                    sling:resourceType="granite/ui/components/coral/foundation/form/textarea"
                                                    fieldLabel="Title"
                                                    name="./title"
                                                    required="true"/>
                                                <titleTag
                                                    jcr:primaryType="nt:unstructured"
                                                    sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                                    fieldDescription="For use when not at top of page"
                                                    fieldLabel="Remove H1 SEO tag (keep style)"
                                                    name="./titleTag"
                                                    text="Remove H1 SEO tag (keep style)"
                                                    uncheckedValue="false"
                                                    value="true"/>
                                                
                                                <subtitle
                                                    jcr:primaryType="nt:unstructured"
                                                    sling:resourceType="granite/ui/components/coral/foundation/form/textarea"
                                                    fieldLabel="Subtitle"
                                                    name="./subtitle"/>
                                                <subtitleTag
                                                    jcr:primaryType="nt:unstructured"
                                                    sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                                    fieldLabel="Subtitle Style "
                                                    name="./subtitleTag"
                                                    text="Subtitle Style "
                                                    uncheckedValue="false"
                                                    value="true"/>
                                                
                                                <buttonlist
                                                    granite:class="showhidecontainer"
                                                    jcr:primaryType="nt:unstructured"
                                                    sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
                                                    composite="{Boolean}true"
                                                    fieldLabel="Button"
                                                    validation="button-multifield-validate">
                                                    <granite:data
                                                        jcr:primaryType="nt:unstructured"
                                                        componentname="Button"
                                                        maxlinksallowed="3"/>
                                                    <field
                                                        granite:class="show-hide-button-container"
                                                        jcr:primaryType="nt:unstructured"
                                                        sling:resourceType="granite/ui/components/coral/foundation/container"
                                                        name="./buttonlist">
                                                        <items jcr:primaryType="nt:unstructured">
                                                            <button
                                                                jcr:primaryType="nt:unstructured"
                                                                sling:resourceType="/libs/granite/ui/components/coral/foundation/include"
                                                                path="/apps/cv/division/components/content/button/cq:dialog/content/items/tabs/items/properties/items/columns/items/column"/>
                                                        </items>
                                                    </field>
                                                </buttonlist>
                                            </items>
                                        </field>
                                    </imageTextItems>
                                </items>
                            </column>
                        </items>
                    </imageTextTab>
                </items>
            </tabs>
        </items>
    </content>
</jcr:root>