I have a CheckboxGroup element for filtering out categories of items. The user can select/deselect as they wish, but I want to disallow the user from unselecting everything i.e. at least one check box must be selected at all times. I know how to code the if condition to check the # of checkboxes selected, but unsure what to put in this if statement to force one checkbox to be on. Any ideas?
Use $w.Element, example:
$w(‘Checkbox’).onChange((event) => {
//handle event this will fired every time when any checkbox data changed
//In here check if there is at least one value from all checkboxes
//If not then do this:
$w('Checkbox')[0].value = $w('Checkbox')[0].options[0];
//upper line will select the first option of first checkbox.
})
If you published your site you can send me your url so I can see your frontend code and help you better.
Thanks Enes, I tried your solution but it kept throwing errors. However, I managed to solve it using the selectedIndices property.