Hi guys, does please know if/how can you show an image on a background that is randomly selected from the collection? I was thinking of using random picker but it seems like it shows only text and if I use an image, it is not a random one. Thanks
It is not clear if you want to show a random image on screen visit or upon pressing a button.
Here is my hack (not elegant but works )
I set up a collection of images. " field in the collection. Image and Name. For name, I entered a number from 1 to 10.
I placed a random picker on the screen that picks a number between 1 and 10. I also put an input field (you can later make this field to be invisible under styles, also 1 by 1 pixel, etc). Once random picker picked a number > update input field with the number.
I placed an image on the screen. I made the image to be a list of images. Max item 1. I also adjusted the list height to show 1 image only. Filter: Image name equals input value.
If you want to make the same if someone clicks a button you could do the following:
Everything same as above except you can remove the random picker and replace it:
On button click > update input value > custom formula > Rand(1,10) where 1 represents the minimum and 10 the max.
If you want to display a random image on button click this option is better:
Place an image and make it a list. Max items: 1
Place an input field
Place a random picker
Image list filter: Name contains input value (it is important to select contains. I tried with equals and it didnt work)
Random picker set up:
Collection : Images (or whatever. Basically the same collection as the image list above)
What happens when user clicks on component?
Pick a new item
Action after refresh:
Update input: Value: Current item’s name.
Hey, thanks for your response! My bad, I want the image to be shows on a background without clicking on anything, make it automatic.
In this case the first idea should give you some inspiration with the random picker + input combo. Are those static images or uploaded by users?
Those images are the ones uploaded by users
Ok here is another solution:
You would need to upload the first image to the database and give it a 6 digit number for example: 100000
Now, when a user uploads an image, you can add a unique ID to the image with the following formula:
This will create 100001, 100002 and so on for every image as it takes the last images maximum Id and add 1 which becomes the current image’s ID.
Add a randomizer component to the screen which generates a number between:
Images>Id>Minimum and Images>Id>Maximum
Once the number is generated you can do an action: update an input field (which you also add to the same screen. Please note you can make the input field invisible by setting the opacity to 0 etc.)
Now you can add an image to the screen and make it a list of images > Max to display:1, ID equals input’s value. Another filter: ID does not equal 100000 (because this was your first image that you uploaded)
Every time a user visits the screen a new number is generated. However if you dont have much images, the component can not guarantee that the same number will not be generated more than 1 time)
Let me know if something is not clear and I’ll try to explain it better.
PS: If you expect a lot of images, you can amend the number of digits up to 10 or whatever)
Thanks a lot for your advice! It sounds a bit difficult but I will give it a though and let you know
Just let me please ask you, I am planning to use that to generate the background for the opening screen, do you think it will work there? And maybe a stupid question but why does the number need to be 6 digits?
It can be any digit. Depends on how many images you will have.
Question: How many images you expect? Are they unique for each user? Are you showing them after log in?
I was planning an unlimited number as users would be able to post them by themselves. Yes, they are unique as each image can be added only by 1 user. Yes, they are shown after log in too
I made an example for you. Cloneable link:
Every time you login / preview the app a new random image is showing up from the user collection
Of course you can hide the input field, it is just for demonstration purposes. I usually make if 1px by 1px with opacity of 0 for all settings. I used an input field because it is faster then writing the database. This trick can also be used for some limited custom states
Thank you very much! Really appreciate that
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.