Hi Community,
I have been struggle with this question.
I have 12 images on my screen. For each image, I have a variant set up so that when I click on it, it greys out. I want to limit the selection to 3 images only, which means that once I have selected 3 images, I should not be able to select any more. How can I achieve this?
Thank you so much!
This is hard, have to map out all possible conditions first and create necessary variables for each of them.
It has the same concept as this one: How to add selection counter, and activate the 'Next' button when 5 options are selected? - #2 by Raphael_M but the other way around.
It gets complicated due to the reason that we’re going to disable the same component, and its not scalable to create 12 different button components because you have 12 images (though this is way way easier—like a trick). The real challenge here is to disable only the non-selected instances but retain the other instances’ in selected while using only 1 button component for scalability purposes.
What I see so far is:
- We’ll need 1 Number variable that tracks how many counts. Set count to 0. Add an click function on the button that changes that variable count to add 1.
- Create 12 different boolean variables for the disable property since there are 12 images and each of them must have their own disable boolean.
- not sure maybe create 12 variables that detects if an image is selected?
Sorry, this all I can see so far. I’ll try to do this when I have time.
1 Like
Thank you so much! I need to get my self familiar with number variable and play around with it.
Maybe I’m missing it, but you’re saying when you select the item it grays out, not that after you pick 3 the other 9 gray out, correct? Just that you can’t select/gray out anymore?
If yes, it’s pretty easy. You set up a number variable and set it to zero. When you click any item, you have an if/else that says if my number variable is less than 3, gray out this item and set my number variable to itself + 1. You could also add a click action on the grayed out state to set it back to normal and subtract 1, that way you could change your mind about which 3 you selected.
1 Like
Thank you both Rapheal and Richard. I am new to Figma so your inputs helped me so much. I was able to figure out after few play around.
I am including the screenshots in case anyone is stuck at the same topic. Make sure follow the same order for variable and check/if for both non greyed out and greyed out images. I initially did the reverse way for the greyed out one, it didn’t work for re-selection.
Indeed. if you do it with 12 different component_sets it will be very easy . But, doing it on a scalable level still not sure. I still have to try it before I can say anything.