Clearing select component in listview

I've been looking around the forum to find ways to clear values of components inside listview components. The answers seem to suggest running a script that loops throughout the indexes, and setting the values of the components back to default inside. I tried this method to clear the select buttons inside my listview with the following code:

for (let i = 0; i < listView5.data.length; i++){
  select1[i].setValue(null);
}

However, it seems that the method setValue is not available for individual entries of the select component (since select1.setValue(null) works just fine, though this only clears the first entry in the listview).

I tried directly setting the value and selectedItem (so something like select1[i].value = null), but the return message says that the attributes are undefined, seemingly indicating that the attributes are private and can't be accessed directly (since the State menu in the sidebar clearly shows that the attributes are actually there).

I'm just curious whether there's any other solutions to this problem. Would greatly appreciate any help. Thanks!

Hey @Nicholas_Alden, welcome to the community.

.setValue() does not work with null. It needs the value specified to be part of the data source, or if custom values to be enabled.

You can use .clearValue() for what you're trying to achieve.

for (let i = 0; i < listView5.instances; i++){
  select1[i].clearValue();
}

Also found out that select1 here is not an array, but an object with the indexes as keys. The State menu on the side portrays it as an array though. Slightly misleading.

image

Hey, thanks for the answer. clearValue() also doesn't seem to be defined the nested object. Similar to before, calling select1.clearValue() instead select1[i].clearValue doesn't return an error, but only clears the first select component.

1 Like

Sorry, there's five and a half dozen different retool versions.

Could you clarify which version you use, and also if you're using the legacy listView component?


.clearValue() works on self-hosted retool with backend 3.20.6.

It sounds like you might be using the new listview, or repeatables, which has a scope limitation:

Scope limitations: for performance reasons, we currently do not support indexing into components inside of a Repeatable to access their properties. Instead, we recommend adding event handlers to track state changes back to data in your Repeatables.

Your looping idea would work in the legacy listview, however:

_.forEach(select1, x=>{x.clearValue()})