Problems with events

I built a few things in Anvil tree years ago, and nor I picked it up again. It is better than ever.

I am building an app to be used in our corporate sports team where the employees can register sporting activities, and get points and win prizes.
It is working, but I want to enchace one thing. For the activities it is possible to choose an icon, a png image, for illustration. I did this in a drop down list with names of the icons, and that was no problem. Now I want to open a form to show all icons, select one and return. I can not fiind out how to return with the icon. I have used all available AI-helpers before I now try here.
The form PoengVelger is where the users click on an icon preview and opens the form VelgIkon where all the icons show up. It has a repeating panel, and in it the for ItemTemplate1 has a flow panel with four images. This works fine to show all the images, until we try to click an icon.

Code Sample:

    def image_click(self, **event_args):
        """Denne metoden kalles når image_1, image_2, image_3, eller image_4 klikkes"""
        clicked_image_component = event_args['sender']
        selected_media_object = clicked_image_component.source

        if selected_media_object:
            print(f"ItemTemplate1: Bilde klikket: {selected_media_object.name}")
            self.raise_event('x-icon-selected', icon_media=selected_media_object)
            print("ItemTemplate1: Event 'x-icon-selected' raised") # Oppdatert print
        else:
            print("ItemTemplate1: Klikket på en tom bildeplass.")

Clone:

Can someone please help me to see what is wrong with the way the ‘x-icon-selected’ is used?

You set the event handler on the repeating panel, which is the parent of the row template. So you want self.parent.raise_event

3 Likes