diff --git a/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/clientlibs/clientlib-it-custom-function/js/functions.js b/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/clientlibs/clientlib-it-custom-function/js/functions.js
index d06dfa3414..7deb535b47 100644
--- a/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/clientlibs/clientlib-it-custom-function/js/functions.js
+++ b/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/clientlibs/clientlib-it-custom-function/js/functions.js
@@ -239,6 +239,8 @@ function customMessageUsingInvalidApi(field, globals) {
}
}
+let label = '',
+ panelLabel = '';
/**
* updatePanelLabel
@@ -247,18 +249,18 @@ function customMessageUsingInvalidApi(field, globals) {
* @param {scope} globals
*/
function updatePanelLabel(repeatablePanel, globals) {
- var label = globals.field.who_lives_name.$label.value;//field is current field
- var panelLabel = globals.field.$label.value;
- var currentIndex = globals.field.$index; // to prevent unnecessary dom update
- globals.functions.setProperty(globals.field,{label : {"value" : panelLabel + (globals.field.$index+1)}}); // on initialize panel label not working right now, will be fixed soon
- globals.functions.setProperty(globals.field.who_lives_name,{label : {"value" : label+""+(globals.field.$index+1)+""}});
+ if (globals.field.$fieldType === 'panel' && label === '') {
+ label = globals.field.who_lives_name.$label.value;
+ panelLabel = globals.field.$label.value;
+ globals.functions.setProperty(globals.field, {label: {"value": panelLabel + (globals.field.$index + 1)}});
+ globals.functions.setProperty(globals.field.who_lives_name, {label: {"value": label + "" + (globals.field.$index + 1) + ""}});
+ }
+
// walk through other instances and update their label
repeatablePanel.$parent.forEach(panel => {
- if (currentIndex != panel.$index) {
- globals.functions.setProperty(panel,{label : {"value" : panelLabel + (panel.$index+1)}});
- globals.functions.setProperty(panel.who_lives_name,{label : {"value" : label+""+(panel.$index+1)+""}});
- }
+ globals.functions.setProperty(panel,{label : {"value" : panelLabel + (panel.$index+1)}});
+ globals.functions.setProperty(panel.who_lives_name,{label : {"value" : label+""+(panel.$index+1)+""}});
});
}
@@ -274,3 +276,18 @@ function addPanelInstance(panel,globals)
{
globals.functions.dispatchEvent(panel,'addInstance', globals.field.$parent.$index + 1);
}
+
+
+/**
+ * Tests remove instance with dispatchEvent
+ * @name removePanelInstance
+ * @param {object} panel
+ * @param {scope} globals
+ */
+function removePanelInstance(panel,globals)
+{
+ globals.functions.dispatchEvent(panel, 'removeInstance', globals.field.$parent.$index);
+ panel.forEach(p => {
+ globals.functions.dispatchEvent(p, 'initialize');
+ })
+}
diff --git a/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/panelcontainer/repeatability-tests/repeatedpanelcount/.content.xml b/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/panelcontainer/repeatability-tests/repeatedpanelcount/.content.xml
index 7fcffb1741..7b56412ed0 100755
--- a/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/panelcontainer/repeatability-tests/repeatedpanelcount/.content.xml
+++ b/it/content/src/main/content/jcr_root/content/forms/af/core-components-it/samples/panelcontainer/repeatability-tests/repeatedpanelcount/.content.xml
@@ -3,10 +3,9 @@
jcr:primaryType="cq:Page">
@@ -88,6 +87,25 @@
+
+
+
+
diff --git a/ui.tests/test-module/specs/repeatable/repeatable.updatelabel.cy.js b/ui.tests/test-module/specs/repeatable/repeatable.updatelabel.cy.js
index 357d5f8deb..e442a68510 100644
--- a/ui.tests/test-module/specs/repeatable/repeatable.updatelabel.cy.js
+++ b/ui.tests/test-module/specs/repeatable/repeatable.updatelabel.cy.js
@@ -30,7 +30,7 @@ describe("Form Runtime with Panel Container", () => {
cy.get(`#${panelId} ${panelLabelSelector}`).should('have.text', panelLabel);
};
- it("add instance should add instance at correct index and label should be correctly updated", () => {
+ it("add and remove instance should add/remove instance at correct index and label should be correctly updated", () => {
expect(formContainer, "formcontainer is initialized").to.not.be.null;
const [buttonid, fieldView] = Object.entries(formContainer._fields)[3];
const [textinputid, fieldView1] = Object.entries(formContainer._fields)[0];
@@ -39,18 +39,26 @@ describe("Form Runtime with Panel Container", () => {
checkLabelText(textinputid, panelid, 'Text Input1', 'Panel1');
cy.get(`#${buttonid}`).find("button").click().then(() => {
- const [textinputid1, fieldView3] = Object.entries(formContainer._fields)[4];
- const [panelid1, fieldView4] = Object.entries(formContainer._fields)[5];
+ const [textinputid1, fieldView3] = Object.entries(formContainer._fields)[5];
+ const [panelid1, fieldView4] = Object.entries(formContainer._fields)[6];
const [buttonid1, fieldView5] = Object.entries(formContainer._fields)[3];
+ const [removeButton, removeFieldView] = Object.entries(formContainer._fields)[4];
checkLabelText(textinputid1, panelid1, 'Text Input2', 'Panel2');
cy.get(`#${buttonid1}`).find("button").click().then(() => {
- const [textinputid2, fieldView6] = Object.entries(formContainer._fields)[7];
- const [panelid2, fieldView7] = Object.entries(formContainer._fields)[8];
+ const [textinputid2, fieldView6] = Object.entries(formContainer._fields)[9];
+ const [panelid2, fieldView7] = Object.entries(formContainer._fields)[10];
checkLabelText(textinputid1, panelid1, 'Text Input3', 'Panel3');
checkLabelText(textinputid2, panelid2, 'Text Input2', 'Panel2');
+
+ // remove instance and check label update
+ cy.get(`#${removeButton}`).find("button").click().then(() => {
+ const [textinputid11, fieldView10] = Object.entries(formContainer._fields)[4];
+ const [panelid11, fieldView11] = Object.entries(formContainer._fields)[5];
+ checkLabelText(textinputid11, panelid11, 'Text Input2', 'Panel2');
+ });
});
});
});