Have been coding now for a few months using Velo. Getting close to the end of my page with over 1000 lines of code. However stuck on a checkbox group issue. I have searched high and low for a solution with no luck.
My design requires one or two specific items in a checkbox group to be checked off with no possibility to uncheck it. My first thought was to disable but display just the boxes I want to remain checked. But I could not find any Velo documentation how to do that. So I went to plan B shown below.
The checkbox group has three boxes, all checked at the start. The second box in the group must always be checked, hence the use of “1” in the code. The code detects if the 2nd box has been unchecked, and tries to reset it back to “checked”. However, the reset also “unchecks” all other boxes which is incorrect. Here is one version of several code versions I have tried.
I have been playing around with this for many hours and cannot figure out how to do what I need.
Hope I described it thoroughly enough for someone to help me. Many thanks.
export function checkboxGroup1_click ( event ) {
let selectedIndices = $w ( “#checkboxGroup1” ). selectedIndices ;
if ( selectedIndices . includes ( 1 ) ) {
console . log ( '…selected index does include ’ , 1 )
} else {
console . log ( '…selected index does NOT include ’ , 1 )
console . log ( ‘Before adding 1 :’ , selectedIndices )
$w ( “#checkboxGroup1” ). selectedIndices = [ 1 ];
console . log ( ‘After adding 1 :’ , selectedIndices )
}
}