Skip to content

Commit 80e41c7

Browse files
pavi41Pavitra Khatri
andauthored
Issue with long description text and introduce data-name attribute in radiobutton (#1522)
Co-authored-by: Pavitra Khatri <pavitrakhatri@pavitras-mbp.corp.adobe.com>
1 parent e8c2461 commit 80e41c7

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/radiobutton/v1/radiobutton/clientlibs/site/js/radiobuttonview.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@
177177
}
178178

179179
#syncWidgetName() {
180+
const name = this.getModel()?.name;
180181
this.widget.forEach(widget => {
181-
widget.setAttribute("name", this.id + "_name");
182+
widget.setAttribute("name", `${this.id}_${name}`);
182183
});
183184
}
184185
}

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/radiobutton/v1/radiobutton/radiobutton.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
data-cmp-enabled="${radioButton.enabled ? 'true' : 'false'}"
3030
data-cmp-required="${radioButton.required ? 'true': 'false'}"
3131
data-cmp-readonly="${radioButton.readOnly ? 'true' : 'false'}"
32+
data-name="${radioButton.name}"
3233
id="${radiobutton.id}"
3334
data-cmp-data-layer="${radioButton.data.json}"
3435
data-cmp-adaptiveformcontainer-path="${formstructparser.formContainerPath}"

ui.frontend/src/view/FormFieldBase.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,17 +636,18 @@ class FormFieldBase extends FormField {
636636
}
637637

638638
// Find the existing <p> element
639-
let pElement = descriptionElement.querySelector('p');
639+
let pElements = descriptionElement.querySelectorAll('p');
640640

641-
if (!pElement) {
641+
if (!pElements) {
642642
// If no <p> tag exists, create one and set it as the content
643-
pElement = document.createElement('p');
643+
pElements = document.createElement('p');
644644
descriptionElement.innerHTML = ''; // Clear existing content
645645
descriptionElement.appendChild(pElement);
646646
}
647647

648648
// Update the <p> element's content with sanitized content
649-
pElement.innerHTML = sanitizedDescriptionText;
649+
pElements.length === 1 ? (pElements[0].innerHTML = sanitizedDescriptionText) : null;
650+
650651
} else {
651652
// If no description was set during authoring
652653
this.#addDescriptionInRuntime(sanitizedDescriptionText);

ui.tests/test-module/specs/prefill/customprefill.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Custom Prefill Test', function () {
2727
const nameTextBox = "input[name='name']",
2828
dobDropdown = "input[name='dob']",
2929
jobDropdown = "select[name='job']";
30-
let genderRadioButton = "input[name='radiobutton-c8c660bac8_name']";
30+
let genderRadioButton = "input[name='radiobutton-c8c660bac8_gender']";
3131
let formContainer = null;
3232

3333
beforeEach(() => {

ui.tests/test-module/specs/radiobutton/radiobutton.runtime.cy.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ describe("Form with Radio Button Input", () => {
7979
});
8080
});
8181

82+
it("should have data-name attribute in parent div matching model name", () => {
83+
const [radioButton1, radioButton1FieldView] = Object.entries(formContainer._fields)[0];
84+
const modelName = radioButton1FieldView.getModel().name;
85+
cy.get(`#${radioButton1}`).invoke('attr', 'data-name').should('eq', modelName);
86+
});
87+
88+
it("should set proper name attribute for radio buttons", () => {
89+
const [id, fieldView] = Object.entries(formContainer._fields)[0];
90+
const model = formContainer._model.getElement(id);
91+
const expectedName = `${id}_${model.name}`;
92+
93+
cy.get(`#${id}`).find(".cmp-adaptiveform-radiobutton__option__widget").each(($radio) => {
94+
cy.wrap($radio).should('have.attr', 'name', expectedName);
95+
});
96+
});
97+
8298
it("radiobutton html changes are reflected in model", () => {
8399
const [id, fieldView] = Object.entries(formContainer._fields)[1];
84100
const model = formContainer._model.getElement(id);

0 commit comments

Comments
 (0)