Skip to content

Commit 207226c

Browse files
pavi41Pavitra Khatri
andauthored
Read-only support in checkbox component (#1446)
Co-authored-by: Pavitra Khatri <pavitrakhatri@Pavitras-MacBook-Pro.local>
1 parent 24076d5 commit 207226c

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/checkbox/v1/checkbox/_cq_dialog/.content.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@
105105
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
106106
fieldLabel="Default value"
107107
name="./default"/>
108-
<readonly
109-
jcr:primaryType="nt:unstructured"
110-
sling:hideResource="{Boolean}true" />
111108
</items>
112109
</column>
113110
</items>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
title="${checkbox.tooltipVisible ? '' : checkbox.tooltipText}"
4343
name="${checkbox.name}"
4444
value="${checkbox.default[0]}"
45-
disabled="${!checkbox.enabled}" />
45+
disabled="${!checkbox.enabled || checkbox.readOnly}" />
4646

4747
<div data-sly-call="${label.label @componentId=widgetId, labelValue=checkbox.label.value, labelVisible=checkbox.label.visible, labelRichText=checkbox.label.richText, bemBlock='cmp-adaptiveform-checkbox'}" data-sly-unwrap></div>
4848
</div>

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,29 @@
6868
getTooltipDiv() {
6969
return this.element.querySelector(CheckBox.selectors.tooltipDiv);
7070
}
71+
72+
updateEnabled(enabled, state) {
73+
if (this.widget) {
74+
this.element.setAttribute(FormView.Constants.DATA_ATTRIBUTE_ENABLED, enabled);
75+
const isDisabled = !enabled || state.readOnly;
76+
if (isDisabled) {
77+
this.widget.setAttribute("disabled", "disabled");
78+
} else {
79+
this.widget.removeAttribute("disabled");
80+
}
81+
}
82+
}
83+
84+
updateReadOnly(readonly) {
85+
if (this.widget) {
86+
this.element.setAttribute(FormView.Constants.DATA_ATTRIBUTE_READONLY, readonly);
87+
if (readonly === true) {
88+
this.widget.setAttribute(FormView.Constants.HTML_ATTRS.DISABLED, "disabled");
89+
} else {
90+
this.widget.removeAttribute(FormView.Constants.HTML_ATTRS.DISABLED);
91+
}
92+
}
93+
}
7194
}
7295

7396
FormView.Utils.setupField(({element, formContainer}) => {

ui.tests/test-module/specs/checkbox/checkbox.authoring.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('Page - Authoring', function () {
5151
cy.get("[name='./name']")
5252
.should("exist");
5353
cy.get("[name='./readOnly']")
54-
.should("not.exist");
54+
.should("exist");
5555
cy.get('.cq-dialog-cancel').should('be.visible').click({ force: true });
5656
cy.get('.cq-dialog-cancel').should('not.exist');
5757
cy.deleteComponentByPath(checkboxDrop);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ describe("Form Runtime with CheckBox Input", () => {
7373
}).then(() => {
7474
model.enable = false
7575
return checkHTML(model.id, model.getState())
76+
}).then(() => {
77+
model.readOnly = true
78+
cy.get(`#${id}`).find(".cmp-adaptiveform-checkbox__widget").should('have.attr', 'disabled', 'disabled');
79+
return checkHTML(model.id, model.getState());
7680
})
7781
});
7882

0 commit comments

Comments
 (0)