Checkbox in ListView, help with accessing and concepts

Goal: Access checkbox within ListView

Though I've got a fair bit of programming experience, it isn't in JS. I've built a couple things in Retool. AI doesn't seem to be helping me. I think I am missing out on some key concepts and appreciate any solutions or teaching.

I've got a container. It contains a ListView. That listview has a single component, a checkbox with label, in it.

When I connect my data, I see the listview populate as I would expect. What that means is I see a list of checkboxes and next to each box is a unique order number.

There are a few things I want to do with the checkbox. Right now, I want to simply generate a JSON of checked checkboxes when I click a button.

So I have a JS Query set up. It runs when I click a button.

The code in the JS query, that is where I'm failing.

Starting real simple, I simple want to see the value of the first checkbox.

I type the following:
return checkbox_order[0].value;

When I mouse over "checkbox_order" I see what looks like the data.
I hit run, I get an Error: Cannot read properties of undefined (reading 'value')

I change it to: return checkbox_order[1].value;
When I mouse over I still see the same data I saw with [0].

In the Debug I can see checkbox_order in State and it is an array.

So in the console I type: checkbox_order[0].value;
and get: checkbox_order can only be referenced in listView_orders because it may not always be available due to performance optimizations.

I read the help article, and I understand some the scope, but not the notation.
listView_orders.data[0]; just returns the data.
listView_orders.data[0].checkbox_order; says it is undefined.

So what is the notation to access checkboxes in a listview?

Hey @Awestruck,

You have to enable instance values in your listView so that you can access that instanceValues property and use the index accordingly.

Here's a similar topic where I've also posted a YouTube video on this.

Hi @MiguelOrtiz

Thank you for the reply.

So I've enabled instance values.

I stumbled a bit more and finally refreshed my browser window and only then did I see the checkbox show up in the instancevalues in the debug/state. Strange.

I appreciate the time to point me in the right direction.

1 Like