Skip to content

Commit ae88d9f

Browse files
dmaurya929demaurya
authored andcommitted
FORMS-12667 Update type property on replacing checkboxgroup to radio group (#1176)
* Update type property on replacing checkboxgroup to radio group * FORMS-12667 review comment --------- Co-authored-by: demaurya <[email protected]>
1 parent 67bfdf4 commit ae88d9f

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

examples/ui.apps/src/main/content/jcr_root/apps/forms-components-examples/components/form/radiobutton/_cq_template.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
jcr:primaryType="nt:unstructured"
44
jcr:title="Radio Button"
55
fieldType="radio-group"
6+
type="number"
67
orientation="horizontal"
78
enum="[0,1]"
89
enumNames="[Item 1,Item 2]"/>

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/editorhook/js/componentutils.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
);
3535
};
3636

37+
function getComponentModel(componentPath) {
38+
const result = $.ajax({
39+
type: 'GET',
40+
async: false,
41+
url: Granite.HTTP.externalize(componentPath + ".model.json"),
42+
cache: false
43+
});
44+
return result.responseJSON;
45+
}
46+
3747
let RequestManager = {};
3848
RequestManager.PostRequest = function () {
3949
RequestManager.Request.call(this, arguments);
@@ -52,17 +62,26 @@
5262
RequestManager.PostRequest.prototype.prepareReplaceParagraph = function (config, editable, preservedProperties) {
5363
if (config.templatePath) {
5464
let comTemplatePath = Granite.HTTP.externalize(config.templatePath),
55-
comData = CQ.shared.HTTP.eval(comTemplatePath + ".infinity.json"); // get component default json
65+
comData = CQ.shared.HTTP.eval(comTemplatePath + ".infinity.json"), // get component default json
66+
updatedProps = {};
67+
68+
if(comData?.fieldType === "radio-group") {
69+
const model = getComponentModel(editable.path);
70+
if(model.type && model.type.includes("[]")) {
71+
updatedProps.type = model.type.replace("[]", "");
72+
}
73+
}
5674

57-
// Delete properties that are not preserved
75+
// Delete properties that are preserved
5876
for (let p in comData) {
5977
if ((!Array.isArray(comData[p]) && typeof comData[p] === 'object') || preservedProperties.includes(p)) {
6078
delete comData[p];
6179
}
6280
}
6381

6482
comData["sling:resourceType"] = config.resourceType;
65-
this.setParam(":content", JSON.stringify(comData)); // write component properties
83+
updatedProps = {...comData, ...updatedProps};
84+
this.setParam(":content", JSON.stringify(updatedProps)); // write component properties
6685
}
6786

6887
// overwrite editable properties with component properties so that data is not lost while replace operation

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/editorhook/js/replacehook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
}
4545

4646
const preservedProperties = ['id', 'description', 'enabled', 'jcr:created', 'jcr:title', 'name',
47-
'placeholder', 'readOnly', 'required', 'tooltip', 'visible', 'enum', 'enumNames'];
47+
'placeholder', 'readOnly', 'required', 'tooltip', 'visible', 'enum', 'enumNames', 'type'];
4848

4949
const cannotBeReplacedWith = ['file-input'],
5050
irreplaceable = ['file-input'],

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
jcr:primaryType="nt:unstructured"
44
jcr:title="Radio Button"
55
fieldType="radio-group"
6+
type="number"
67
orientation="horizontal"
78
enum="[0,1]"
89
enumNames="[Item 1,Item 2]"/>

ui.tests/test-module/specs/replaceaction/replacelayout-container.authoring.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,15 @@ describe('component replace - Authoring', function () {
147147
cy.get("[value='" + afConstants.components.forms.resourceType[type] + "']").should('not.exist');
148148
}
149149
}
150+
cy.intercept('POST', /core-components-it\/blank\/jcr:content\/guideContainer\/.*/).as('replaceCmp');
150151
cy.get(replacementComp).click();
152+
cy.wait("@replaceCmp");
153+
if(replacedComponentName === radioButtonName) {
154+
cy.getFormJson("/content/forms/af/core-components-it/blank/jcr:content/guideContainer/checkboxgroup").then((body) => {
155+
expect(body).to.have.property('type');
156+
expect(body.type).eq("number");
157+
})
158+
}
151159
cy.deleteComponentByTitle(replacedComponentName);
152160
}
153161
}

0 commit comments

Comments
 (0)