Wix Corvid: CheckboxGroup: Where's the 'checked' property?

Viewed 634

Purpose: I need to programatically set the "checked" property of certain CheckboxGroup options.

I understand that a CheckboxGroup contains an options Array, each option containing a name and a value.

I am having trouble understanding how Wix reads and writes the checked property of each option. As far as I can tell, that does not exist.

A) Does Wix automatically generate a Checkbox for every option? If so, how do I access those Checkboxes and set the .checked property?

B) If not, then how does a dataset read the checked property on each option of a CheckboxGroup?

2 Answers

CheckboxGroup has a property called "selectedIndices", which is an array with the indices of selected items. By setting this property, the proper values are selected.

To answer your questions, Corvid views the ChecboxGroup in the same way that it looks at an array of selectable options in dropdown or radiogroup, except for the fact that you can select more than one.

So in order to select the options in your ChecboxGroup element, "#checkboxGroup", you would need to provide an array of values that match the options. E.g.

$w("#checkboxGroup").options = [
  {"label": "JavaScript", "value": "js"},
  {"label": "Python", "value": "python"},
  {"label": "Node.js", "value": "node"}
];

To set JavaScript and Node.js to checked, you would do:

$w("#checkboxGroup").value = ["js","node"];
Related