If I am making the checkbox default checked using coral2 checkbox field,
<enableBanner
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/checkbox"
fieldDescription="Check if shorter banner is required."
listener="toggle.checkboxShorterBanner"
name="./enableBanner"
text="Shorter Banner"
uncheckedValue="false"
value="true"
defaultChecked="{Boolean}true"/>
and in SlingModel using it
@ValueMapValue
@Default(booleanValues = true)
private boolean enableBanner;
Sightly code
I want to add shortHeroClass if it is checked otherwise no
I can see the difference in html where it is coming as checked by default
<div class="coral-Form-fieldwrapper coral-Form-fieldwrapper--singleline"><label class="coral-Checkbox coral-Form-field">
<input type="checkbox" name="./shorterBanner" value="true" data-validation="" checked="" class="coral-Checkbox-input" data-listener="toggle.checkboxShorterBanner">
where it is not coming as checked by default, checked="" is not coming in html
<div class="coral-Form-fieldwrapper coral-Form-fieldwrapper--singleline"><label class="coral-Checkbox coral-Form-field">
<input type="checkbox" name="./enableBanner" value="true" data-validation="" class="coral-Checkbox-input" data-listener="toggle.checkboxShorterBanner">
But on this page if I am dragging dropping this component, then it is showing checkbox checked by default
I also want to show hide tab based on checkbox selection
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @vineetgupta,
The defaultChecked="{Boolean}true" attribute only sets the initial value when no value is stored in the JCR.
If an existing page already has the property enableBanner (even as false or empty), the dialog will render based on the stored value, not the defaultChecked value.
Here is what coming in my mind:
1. Fix existing content nodes
To force all existing pages to have enableBanner=true (checked by default), you can run a JCR content update (via Groovy script, ACS Commons Bulk Editor, or a query).
Example Groovy script:
def rootPath = "/content/your-site"
def nodes = getNode(rootPath).recurse().findAll { it.hasNode("enableBanner") == false }
nodes.each {
it.setProperty("enableBanner", true)
}
This ensures that older pages have enableBanner set correctly.
2. Use @Default(booleanValues = true) in SlingModel
You are already using:
@ValueMapValue
@Default(booleanValues = true)
private boolean enableBanner;
This is good - it ensures that if the property is missing in JCR, the model returns true.
However, in Sightly/HTL, you should reference bannerPowerModel.enableBanner instead of properties.isBanner to ensure the model's logic takes precedence.
Hi @vineetgupta,
The defaultChecked="{Boolean}true" attribute only sets the initial value when no value is stored in the JCR.
If an existing page already has the property enableBanner (even as false or empty), the dialog will render based on the stored value, not the defaultChecked value.
Here is what coming in my mind:
1. Fix existing content nodes
To force all existing pages to have enableBanner=true (checked by default), you can run a JCR content update (via Groovy script, ACS Commons Bulk Editor, or a query).
Example Groovy script:
def rootPath = "/content/your-site"
def nodes = getNode(rootPath).recurse().findAll { it.hasNode("enableBanner") == false }
nodes.each {
it.setProperty("enableBanner", true)
}
This ensures that older pages have enableBanner set correctly.
2. Use @Default(booleanValues = true) in SlingModel
You are already using:
@ValueMapValue
@Default(booleanValues = true)
private boolean enableBanner;
This is good - it ensures that if the property is missing in JCR, the model returns true.
However, in Sightly/HTL, you should reference bannerPowerModel.enableBanner instead of properties.isBanner to ensure the model's logic takes precedence.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies