Prevent unselecting a value in table cell options list

  • Goal: Prevent unselecting a value in table cell mapped options list

  • Details: I'm using a table component with an editable cell. The cell's fomat is Tag and uses the "Option list" add-on. I want to prevent users from being able to deselect an item

I cannot seem to find any type of Validation or Required options for an "options list" in a cell.

Welcome to the community!

I don't think there will be a way to prevent the deselect using the inline editor - these are some ideas off the top of my head about what you could do, depending on your preference, requirements, and how it affects the UX :

  1. change the option list to be a mapped list of all values excluding the current selection - my issue here is that you could end up in a situation where the user can only add new items to the list and never remove them, which may not be ideal. Possibly use the sourceRow value as the list of option items to exclude, but this might confuse users

  2. reinstate any removed items manually when the column is changed - my issue with this one is the user will be confused and possibly the table component too, you'd be triggering change events a lot

  3. if they've removed an item then show a "are you sure?" dialog or "sorry you can't do that" message before invalidating the change or do this before the save action maybe

  4. if it's always the same option item that can't be removed (if it's some kind of default) then simply don't show it in that list/column

If none of these sound like they're quite right then please give some more detail on your use case and what options are needed/can be selected/deselected to help find a solution for you

1 Like

Thank you very much!
Right now my solution is to check for a change of that column in the query, and alter the changeset to use the previous value if it is null. It's not ideal, but seems to work.

Regarding option 3 - I wasn't aware of a way to invalidate the edit. Can you tell me how this is done?

Is there a better type than Tag to use? I really just want a dropdown of mapped distinct values to choose from where null is not an option

You can use mytable.clearChangeSet() to remove the changes a user has made and revert it back to the last loaded data set

Thanks, again!
I tried that, but I can't stop the event bubbling, so it leads to other issues. Even if I clear the changes at the cell level, the table level Change Cell still runs (even if i put in 'Only run when: {{ table.changesetArray.length > 0}}'. I'm assuming each event got a copy of the changeset before I reset it or something. I'd love to see more detailed information on how events work in retool

Maybe something like this might be easier, you shouldn't need a cell level event in this case.

The rule here is that you can't have an empty value for Teams

Transformer keeps a track of the validation when the changes are made in the table - a column (could be hidden but to explain it I've made it a boolean) shows if it's valid or not. The save action checks the transformer and decides if the save can happen or not.


forum.json (69.1 KB)

1 Like

I think this idea will work. I'll try it in the next iteration.
Thanks