Expand my Community achievements bar.

SOLVED

How to make selection checkboxes selected by default?

Avatar

Level 7

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.

1 Accepted Solution

Avatar

Correct answer by
Level 6

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

View solution in original post

3 Replies

Avatar

Correct answer by
Level 6

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

Avatar

Level 7

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"?

Avatar

Level 2

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?