Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:dam="http://www.day.com/dam/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:fd="http://www.adobe.com/aemfd/fd/1.0"
jcr:primaryType="dam:Asset">
<jcr:content
cq:conf="\0"
jcr:lastModified="{Date}2024-07-28T15:11:24.872+05:30"
jcr:primaryType="dam:AssetContent"
sling:resourceType="fd/fm/af/render"
guide="1"
type="guide">
<metadata
fd:version="2.1"
jcr:language="en"
jcr:primaryType="nt:unstructured"
xmp:CreatorTool="AEM Forms AF Wizard"
allowedRenderFormat="HTML"
author="admin"
dorType="none"
formmodel="none"
themeRef="/libs/fd/af/themes/canvas"
title="Add instances via loop"/>
</jcr:content>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:fd="http://www.adobe.com/aemfd/fd/1.0"
jcr:primaryType="cq:Page">
<jcr:content
cq:deviceGroups="[/etc/mobile/groups/responsive]"
cq:lastModified="{Date}2024-07-28T15:11:24.873+05:30"
cq:lastModifiedBy="admin"
cq:template="/conf/core-components-examples/settings/wcm/templates/af-blank-v2"
jcr:language="en"
jcr:primaryType="cq:PageContent"
jcr:title="Add instances via loop"
sling:configRef="/conf/forms/add-instances-via-loop/"
sling:resourceType="forms-components-examples/components/page"
ignoreTranslationInvalidation="{Boolean}true">
<guideContainer
fd:version="2.1"
jcr:primaryType="nt:unstructured"
sling:resourceType="forms-components-examples/components/form/container"
dorType="none"
fieldType="form"
thankYouOption="page"
themeRef="/libs/fd/af/themes/canvas"
title="Add instances via loop">
<panelcontainer
jcr:created="{Date}2024-07-28T15:10:40.615+05:30"
jcr:createdBy="admin"
jcr:lastModified="{Date}2024-07-28T15:11:24.871+05:30"
jcr:lastModifiedBy="admin"
jcr:primaryType="nt:unstructured"
jcr:title="Panel"
sling:resourceType="forms-components-examples/components/form/panelcontainer"
enabled="{Boolean}true"
fieldType="panel"
hideTitle="false"
name="panelcontainer"
readOnly="{Boolean}false"
repeatable="true"
textIsRich="[true,true,true]"
visible="{Boolean}true"
wrapData="{Boolean}false">
<checkboxgroup
jcr:created="{Date}2024-07-28T15:11:03.827+05:30"
jcr:createdBy="admin"
jcr:lastModified="{Date}2024-07-28T15:11:19.032+05:30"
jcr:lastModifiedBy="admin"
jcr:primaryType="nt:unstructured"
jcr:title="Check Box Group"
sling:resourceType="forms-components-examples/components/form/checkboxgroup"
enabled="{Boolean}true"
enum="[0,1]"
enumNames="[Item 1, Item 2]"
fieldType="checkbox-group"
hideTitle="false"
name="checkbocx"
orientation="horizontal"
readOnly="{Boolean}false"
textIsRich="[true,true,true,true,true]"
type="string[]"
unboundFormElement="{Boolean}false"
visible="{Boolean}true"/>
</panelcontainer>
</guideContainer>
</jcr:content>
</jcr:root>
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,17 @@
result.parentElement = this.element;
}
} else {
var previousInstanceElement = instanceManager.children[instanceIndex - 1].element;
var previousInstanceItemDiv = this.#getItemById(previousInstanceElement.id + Accordion.idSuffixes.item);
result.beforeViewElement = previousInstanceItemDiv;
let previousInstanceElement = this.#getRepeatableElementAt(instanceManager, instanceIndex - 1);
result.beforeViewElement = previousInstanceElement;
}
return result;
}

#getRepeatableElementAt(instanceManager, index) {
let childId = instanceManager._model.items.find((model) => model.index === index)?.id;
return this.element.querySelector(`#${childId}${Accordion.idSuffixes.item}`);
}

#prepareAccordionMarkupToBeAdded(instanceManager, addedModel, htmlElement) {
var accordionItemDivToBeRepeated = this._templateHTML[instanceManager.getId()]['accordionItemDiv'].cloneNode(true);
var itemDivId = accordionItemDivToBeRepeated.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@
this.element.setAttribute("data-cmp-required", required);
}
}

syncMarkupWithModel() {
super.syncMarkupWithModel();
this.updateEnum(this._model.enum);
this.updateEnumNames(this._model.enumNames);
}
}

FormView.Utils.setupField(({element, formContainer}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@
result.parentElement = this._templateHTML['divToAppendChild'];
}
} else {
var previousInstanceElement = instanceManager.children[instanceIndex - 1].element;
var previousInstanceItemDiv = this.#getCachedElementById(previousInstanceElement.id).parentElement;
let previousInstanceItemDiv = instanceManager.getElementAt(instanceIndex - 1);
result.beforeViewElement = previousInstanceItemDiv;
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,20 @@
const tabs = this.#getCachedTabs();
if (wizardPanels) {
for (let i = 0; i < wizardPanels.length; i++) {
if (i === parseInt(this.#_active)) {
wizardPanels[i].classList.add(Wizard.selectors.active.wizardpanel);
wizardPanels[i].removeAttribute(FormView.Constants.ARIA_HIDDEN);
tabs[i].classList.add(Wizard.selectors.active.tab);
tabs[i].setAttribute(FormView.Constants.ARIA_SELECTED, true);
tabs[i].setAttribute(FormView.Constants.TABINDEX, "0");
} else {
wizardPanels[i].classList.remove(Wizard.selectors.active.wizardpanel);
wizardPanels[i].setAttribute(FormView.Constants.ARIA_HIDDEN, true);
tabs[i].classList.remove(Wizard.selectors.active.tab);
tabs[i].setAttribute(FormView.Constants.ARIA_SELECTED, false);
tabs[i].setAttribute(FormView.Constants.TABINDEX, "-1");
if(tabs[i]) {
if (i === parseInt(this.#_active)) {
wizardPanels[i].classList.add(Wizard.selectors.active.wizardpanel);
wizardPanels[i].removeAttribute(FormView.Constants.ARIA_HIDDEN);
tabs[i].classList.add(Wizard.selectors.active.tab);
tabs[i].setAttribute(FormView.Constants.ARIA_SELECTED, true);
tabs[i].setAttribute(FormView.Constants.TABINDEX, "0");
} else {
wizardPanels[i].classList.remove(Wizard.selectors.active.wizardpanel);
wizardPanels[i].setAttribute(FormView.Constants.ARIA_HIDDEN, true);
tabs[i].classList.remove(Wizard.selectors.active.tab);
tabs[i].setAttribute(FormView.Constants.ARIA_SELECTED, false);
tabs[i].setAttribute(FormView.Constants.TABINDEX, "-1");
}
}
}
}
Expand Down Expand Up @@ -617,13 +619,17 @@
result.beforeViewElement = this.getPreviousButtonDiv();
}
} else {
let previousInstanceElement = instanceManager.children[instanceIndex - 1].element;
let previousInstanceWizardPanelIndex = this.#getTabIndexById(previousInstanceElement.id + Wizard.#tabIdSuffix);
result.beforeViewElement = this.#getCachedWizardPanels()[previousInstanceWizardPanelIndex];
let previousInstanceElement = this.#getRepeatableElementAt(instanceManager, instanceIndex - 1)
result.beforeViewElement = previousInstanceElement;
}
return result;
}

#getRepeatableElementAt(instanceManager, index) {
let childId = instanceManager._model.items.find((model) => model.index === index)?.id;
return this.element.querySelector(`#${childId}${Wizard.#wizardPanelIdSuffix}`);
}

updateChildVisibility(visible, state) {
this.updateVisibilityOfNavigationElement(this.#getTabNavElementById(state.id + Wizard.#tabIdSuffix), visible);
let activeTabNavElement = this.#getCachedTabs()[this.#_active];
Expand Down
41 changes: 24 additions & 17 deletions ui.frontend/src/view/FormTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,23 @@ class FormTabs extends FormPanel {
var tabs = this.#getCachedTabs();
if (tabpanels) {
for (var i = 0; i < tabpanels.length; i++) {
if (tabs[i].id === this.#_active) {
tabpanels[i].classList.add(this.#_selectors.active.tabpanel);
tabpanels[i].removeAttribute(Constants.ARIA_HIDDEN);
tabs[i].classList.add(this.#_selectors.active.tab);
tabs[i].setAttribute(Constants.ARIA_SELECTED, true);
tabs[i].setAttribute(Constants.TABINDEX, "0");
tabs[i].setAttribute(Constants.ARIA_CURRENT, "true");
} else {
tabpanels[i].classList.remove(this.#_selectors.active.tabpanel);
tabpanels[i].setAttribute(Constants.ARIA_HIDDEN, true);
tabs[i].classList.remove(this.#_selectors.active.tab);
tabs[i].setAttribute(Constants.ARIA_SELECTED, false);
tabs[i].setAttribute(Constants.TABINDEX, "-1");
tabs[i].setAttribute(Constants.ARIA_CURRENT, "false");
// In case of repeatability ( adding instance via loop) tabs and tabpanels may be out of sync, it will sync in future
if(tabs[i]) {
if (tabs[i].id === this.#_active) {
tabpanels[i].classList.add(this.#_selectors.active.tabpanel);
tabpanels[i].removeAttribute(Constants.ARIA_HIDDEN);
tabs[i].classList.add(this.#_selectors.active.tab);
tabs[i].setAttribute(Constants.ARIA_SELECTED, true);
tabs[i].setAttribute(Constants.TABINDEX, "0");
tabs[i].setAttribute(Constants.ARIA_CURRENT, "true");
} else {
tabpanels[i].classList.remove(this.#_selectors.active.tabpanel);
tabpanels[i].setAttribute(Constants.ARIA_HIDDEN, true);
tabs[i].classList.remove(this.#_selectors.active.tab);
tabs[i].setAttribute(Constants.ARIA_SELECTED, false);
tabs[i].setAttribute(Constants.TABINDEX, "-1");
tabs[i].setAttribute(Constants.ARIA_CURRENT, "false");
}
}
}
}
Expand Down Expand Up @@ -544,13 +547,17 @@ class FormTabs extends FormPanel {
result.beforeViewElement = this.#getTabListElement();
}
} else {
var previousInstanceElement = instanceManager.children[instanceIndex - 1].element;
var previousInstanceTabPanelIndex = this.#getTabIndexById(previousInstanceElement.id + this.#tabIdSuffix);
result.beforeViewElement = this.#getCachedTabPanels()[previousInstanceTabPanelIndex];
let previousInstanceElement = this.#getRepeatableElementAt(instanceManager, instanceIndex - 1);
result.beforeViewElement = previousInstanceElement;
}
return result;
}

#getRepeatableElementAt(instanceManager, index) {
let childId = instanceManager._model.items.find((model) => model.index === index)?.id;
return this.element.querySelector(`#${childId}${this.#tabPanelIdSuffix}`);
}

/**
* Gets the child view at the specified index.
* @param {number} index - The index of the child view.
Expand Down
18 changes: 17 additions & 1 deletion ui.frontend/src/view/InstanceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,29 @@ class InstanceManager {
let afterElement = this.children[0].element.parentElement;
this.parentElement.insertBefore(htmlElement, afterElement);
} else {
let beforeViewElement = (beforeElement != null) ? beforeElement : this.children[instanceIndex - 1].element.parentElement;
let beforeViewElement = this.getElementAt(instanceIndex - 1);
beforeViewElement.after(htmlElement);
}
}
return htmlElement;
}

/**
* Gets the HTML element at the given index
* @param index {number} The index of the element
* @returns {Element}
*/
getElementAt(index) {
let childModel = this._model.items.find((model) => model.index === index);
let viewElement = this.parentElement.querySelector(`#${childModel.id}`);
if (viewElement) {
while (viewElement.parentElement !== this.parentElement) {
viewElement = viewElement.parentElement;
}
}
return viewElement;
}

/**
* Removes HTML for the removed instance
* @param removedInstanceView {object} The view of the removed instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ describe("Form with Accordion Container with repeatable elements", () => {
})
cy.expectNoConsoleErrors();
})

it('test adding panel programmatically', () => {
getItemDivs().should('have.length', 5);
getAccordionPanels().should('have.length', 5);
getAccordionButtons().should('have.length', 5);
cy.wrap(null).then(() => {
const instanceManager = formContainer._model.items[0].items[0];
for(let i=0; i<4; i++){
instanceManager.dispatch({type: "addItem"})
}
}).then(() => {
getItemDivs().should('have.length', 8);
getAccordionPanels().should('have.length', 8);
getAccordionButtons().should('have.length', 8);
})
});
})

describe("Form with Accordion Container with nested repeatable elements", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright 2024 Adobe
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

describe("Repeatability Tests in Panel Container", () => {
const pagePath = "content/forms/af/core-components-it/samples/panelcontainer/repeatability-tests/add-instances-via-loop.html";

let formContainer = null;

beforeEach(() => {
cy.previewFormWithPanel(pagePath).then(p => {
formContainer = p;
});
});

it("add instance using loop and change checkbox enums", () => {
const instanceManager = formContainer._model.items[0];
const initialNoOfChild = instanceManager.items.length;
expect(initialNoOfChild).to.equal(1);
cy.get(".cmp-adaptiveform-container__wrapper")
.children()
.should("have.length", 1);

cy.wrap(null).then(() => {
for(let i=0; i < 4; i++) {
if(i !== 0) {
instanceManager.dispatch({type: "addItem"});
}
const chbx = instanceManager.items[i].items[0];
chbx.enum = [ "item1" + i, "item2" + i];
chbx.enumNames = [ "Item1" + i, "Item2" + i];
}
})

cy.get(".cmp-adaptiveform-container__wrapper > div")
.should("have.length", 4);

cy.wrap(null).then(() => {
for(let i=0; i < 4; i++) {
const chbx = instanceManager.items[i].items[0];
expect(chbx.enum).to.deep.equal([ "item1" + i, "item2" + i]);
expect(chbx.enumNames).to.deep.equal([ "Item1" + i, "Item2" + i]);
cy.get("#" + chbx.id + " [value='item1" + i + "']")
.should("be.visible");
cy.get("#" + chbx.id + " [value='item2" + i + "']")
.should("be.visible");
}
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,18 @@ describe("Form with TabsOnTop Container", () => {
})
})

it('test adding panel programmatically', () => {
getTabs().should('have.length', 4);
getTabPanels().should('have.length', 4);
cy.wrap(null).then(() => {
const instanceManager = formContainer._model.items[0].items[0];
for(let i=0; i<5; i++){
instanceManager.dispatch({type: "addItem"})
}
}).then(() => {
getTabs().should('have.length', 7);
getTabPanels().should('have.length', 7);
})
});

})
Loading