Hi. Is there a way to programatically get the name of a component?
Example: User clicks on a button and the name of that button would be a variable value.
Thanks
I was actually going to suggest a component labelling option, but I find setting background picture resize mode to the value. Or some sort of variable of the component that you arenāt using. Of course if you are using that value then your other options would be to set things like text (if the text is invisible) or set background picture if there is no picture.
For the information above, I assumed you are using buttons.
(edit)
For me, Thunkable keeps the component settings default if the settings you inserted arenāt to the format required. So the background picture resize mode could = āoption-1ā.
Edit: oops! You want the name. Hmm, no, I donāt think so. I read this too quickly. Sorry!
You can get the button ID. This topic explains how:
Itās a little more detailed than you might need so hereās a simple way to get that info:
Hi, @yosik!
I have a nice idea for you. When you rename your component, set the new name in the background picture
box as well. Like this -
So, when the button gets clicked, you would get the component name by this -
This will work, because in our case, a buttonās background picture is simply itās component name.
Hope this helps you!
Thanks!
Thanks for responding.
@kartik14, your idea will work only if ALL buttons use the same image. In my case, each button has a different imageā¦But I am keepipng your solution for other projects.
@eoinparkinson, this would work, but as far as dev effort is concerned, it comes out the same as having a different block for each button. In addition, although it is a good workaround, it is not good programming practice. Again, Thank you very much for the thought.
Thunkable Team. I think this is a needed feature and āComponent Nameā should be added as a property to all components.
Cheers,
Yossi
Hi,
Example of working with a component name (Spreadsheet is used to get a nice name for the name of a new property)
Hi @actech ,
I think you misunderstood me.
I am not looking for a way to write text on a Button, I am looking for a way to get the NAME of a button and use it and this is because I do not have any text on my buttons, just images.
TY
Yossi
If you donāt have texts on your images, set the text as transparent, and set the āNameā of the button on the text.
Edit because submitted before end xD : Youāre asking for a solution to what you want but there is no existing one. So youāre forced to do it with workarounds. Also, I didnāt get what you meant by āitās the same as having a different block for each buttonā, you just get the any button clicked event, get the text of the component getting clicked, and push that text into a variable, it looks exactly like what you want, expect if I misunderstood something
In the example below I get the button name and use it. But to do this, you must first explicitly set the name for the button, as you understand.
Other way
@AcrobatEpee and @actech, Thank you. Yes, both of your solutions are working.
Appreciate the effort and the answers.
But @actech, in the second example, arenāt you just created a list with properties for each button name? They arenāt actually associated with particular buttons, are they? So when you need to retrieve a specific button name, you still need to know the button # and then match it to the list element/index.
In the second example, a list of pairs is created, where the component ID is used as the key, and an arbitrary name is used as the value. Therefore, the ID is associated with the name, but the name is not stored in the component. When working with components, we can easily find out its ID, and then use the list of keys to get a predefined name for it. If you did not specify a name for a button, then naturally you cannot use a name for such a button. Similarly, the first option will not work if the property for saving the name was not initially created.
Thanks for explaining. I didnāt realize you were getting the component ID.
Access to a component by name is used in text programming and this is really more convenient than ID, but I believe that we need not just the name of the component, but the ability to use this name to access components located on another screen. I made such a request to the developers, but I do not think that it will ever be realized.