Hello Retool expert:
I am using the new Table component and have a Multiselect Tag column named my_anwers. The data for this table also includes a question_type column (with values like 'single' or 'multi select').
I need to apply validation rules to the my_anwers column on a per-row basis, based on the question_type for that specific row:
-
For 'single' rows: The user should only be allowed to select a maximum of 1 tag.
-
For 'multi select' rows: The user must select a minimum of 2 tags. If they only select one, I need to display a validation warning.
I want to accomplish this using a single column to provide a good user experience. I've tried looking for a 'Validation' property that accepts currentRow, but I can't seem to find the right place to implement this logic.
What is the correct way to set dynamic, row-level Min tags and Max tags for a Multiselect Tag column? or how to this function via change event.
thanks a lot.
Hey @Adam_Zhu,
Great question, and definitely something that would be a nice to have in the multiselect tag option.
As far as I know, there is not native way of achieving this, unfortunately.
The way I would approach this would be:
- Use a variable that has as default the data for the table, e.g.
query1.data
- Use such variable as the table's data source
- Upon users editing the multiselect tag, you use variable1.setIn( [index,my_answers], table1.changeSetArray.... etc) which would update the variable
- Have a transformer that verifies each row in the variable data, and validates as x the rules you shared, i.e. if row has single, my_answers should be length =< 1, otherwise return error and message error, which could be also referring to the given row, e.g. "Dear user, you selected two items in row x, please selet only 1". etc
- The output for this transformer would also disable/enable any final submit button, etc.
Does it make sense? Happy to expand more if needed.
1 Like
@MiguelOrtiz
Thanks for your reply. your solution seems a little bit complex.
Iām checking if can have simpler approach.