How to make selection checkboxes selected by default? | Community
Skip to main content
LinearGradient
October 16, 2015
Solved

How to make selection checkboxes selected by default?

  • October 16, 2015
  • 3 replies
  • 5888 views

According to the docs, the optionsConfig can be used for this purpose:

The config of the options components. For selections of type "checkbox" and "radio" optionsConfig will be passed to every single CheckBox or Radio. For "select" and "combobox" optionsConfig will be passed to the underlaying ComboBox.

For checkbox, here's what the docs say about checked:

true if the checkbox should render initially checked (defaults to false)

So for my dialog, I have configured a selection widget like this:

                                <test jcr:primaryType="cq:Widget"
                                                     options="/apps/.../options.json"
                                                     xtype="selection"
                                                     type="checkbox">
                                    <optionsConfig jcr:primaryType="nt:unstructured" checked="{Boolean}true"/>
                                </test>

 

options.json:

[
    {
        "text": "Option 1",
        "value": "option1"
    },
    {
        "text": "Option 2",
        "value": "option2"
    }
]

However this is not causing all the checkboxes to be checked initially.

What is the proper, non-hacky way of doing this?

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ove_Lindström

Use the defaultValue property and insert the values you want to have selected from start. See [1] for an example.

Also, each checkbox is an item of its own and can have the boolean value true (checked) of false (unchecked). This is not radio buttons, right?

/Ove

 

 

[1] http://localhost:4502/crx/de/index.jsp#/libs/foundation/components/list/dialog/items/list/items/feed

3 replies

Ove_LindströmAccepted solution
October 16, 2015

Use the defaultValue property and insert the values you want to have selected from start. See [1] for an example.

Also, each checkbox is an item of its own and can have the boolean value true (checked) of false (unchecked). This is not radio buttons, right?

/Ove

 

 

[1] http://localhost:4502/crx/de/index.jsp#/libs/foundation/components/list/dialog/items/list/items/feed

LinearGradient
October 16, 2015

The difference between my case and that CQ 5 example is that I am rendering multiple checkboxes. Should I set the defaultValue to "option1,option2"?

July 19, 2018

This works in case of options arbitrarily added while creating the dialog.

It doesn't seem to work for options populated via a JSON or servlet.

I have tried <optionsConfig jcr:primaryType="nt:unstructured" checked="{Boolean}true"/> as mentioned above. To set defaultValue property as an array of values, since the options are dynamically generated, is there a way to dynamically set this property "defaultValue"? Or any other approach to have the checkboxes selected initially?