nativescript-checkbox icon indicating copy to clipboard operation
nativescript-checkbox copied to clipboard

viewModel update doesn't toggle the checkbox

Open Whip opened this issue 3 years ago • 0 comments

I'm using this checkbox plugin inside ui-collections list. I want the user to tap the list item anywhere and that should toggle its checkbox but that doesn't happen. The viewModel updates but the checkbox doesn't. I can not get the checkbox view to call the toggle function on it (I don't know how) so I was hoping the checkbox will toggle when its checked state changes. Here's my code

<gv:CollectionView items="{{ list }}" colWidth="49%" id="collection" itemTap="onItemSelected">
  <gv:CollectionView.itemTemplate>
    <GridLayout rows="*,auto" class="bg-trans" margin="5">
    	<i:ImageCacheIt row="0" width="{{ width }}" height="{{ width }}" decodeWidth="{{ width }}" decodeHeight="{{ width }}" progressiveRenderingEnabled="true" src="{{ image }}" placeholderImageUri="~/images/loading.jpg" failureImageUri="~/images/loading.jpg" stretch="aspectFill" />
	<CheckBox:CheckBox row="0" checked="{{ checked }}" text="" verticalAlignment="top" horizontalAlignment="right" fillColor="#363636" id="{{ 'check'+id }}" isUserInteractionEnabled="false" ios:backgroundColor="transparent" ios:width="20" />
    	<StackLayout row="0" verticalAlignment="bottom" class="cat-caption">
    		<Label text="{{ name }}" verticalAlignment="center" />
    	</StackLayout>
    </GridLayout>
  </gv:CollectionView.itemTemplate>
</gv:CollectionView>
export function onItemSelected(args){
  const selectedItem = viewModel.list[args.index];

  if(selectedItem.checked)
    viewModel.list[args.index].checked = false;
  else
    viewModel.list[args.index].checked = true;
}

Is it possible to toggle the checkbox through updating the viewModel?

Whip avatar Dec 19 '21 09:12 Whip