Disable Delete Button if the id is used in another table

Hi, I'm new to retool and I can't seem to figure out how to disable a delete button if the ID is used in another table.
So for example (and this is not what my app is doing, I'm just trying to keep it simple) ...
Table1 fields: userid, firstname, lastname
Table2 fields id, userid, note, datetime

I wouldn't want to delete a row from Table1 if there are are rows in Table2 with that userid

How is that handled in Retool?

That is easy/hard.

Just put some logic in the buttons Disabled property of the button that evaluates to True is the ID is in Table2 (easy.)

Now you need to figure out the logic (harder.) I am not sure from your description how you would obtain the ID to test with, but something like this would work:

{{table2.data.findIndex(el=>el.id === someUserIdFromTable1) > -1}}

This is looping through all records in Table2 and looking for one that has an id matching the variable someUserIdFromTable1. It returns the matching array index or -1 if not found. So the entire line returns true if it finds a match.

Hopefully that gets you the clues you need to get it working.


I had to change it to >= 0 to disable for the first recond.

But thank you, that did it!

1 Like