Visibility/Scope of raise_event

What I’m trying to do:

I have a Form which contains a table. The rows of table calls RowTemplate. In RowTemplate I have a button that saves some information. Currently, I have a line in Form that sets an event handler.

self.set_event_handler('x-refresh-tables', self.Func)

in RowTemplate, I have the raise event line:

self.raise_event('x-refresh-tables')

However, I’ve noticed that Form will not run self.Func even after the event is raised.

My question is, what is visibility/scope of self.raise_event(*)? Are event handles only local to the calling form and not accessible globally? In other words, can any form set an event handler and then lower the event when a raise is called in any other form?

The scope of object.raise_event() is the object itself. However, the event-handler function can be defined in any object.

I commonly run into cases where I need a Form to act on an event raised by a RowTemplate instance. To handle these cases, I tell the RowTemplate to raise the event on its self.parent, i.e., on the RepeatingPanel in the Form.

In order to get that RepeatingPanel to respond, the Form tells it to register a handler, for that custom event. (This must happen before the RowTemplate raises that event.)

The handler itself is a function in the outer Form, so it has access to all of the Form’s attributes.

Commonly, the handler function needs to know information about the specific RowTemplate instance. In that case, the RowTemplate instance can pass its self or self.item (or any other detail) as an additional argument to the handler; and the handler is given an additional parameter, to receive it.

1 Like

Typically, you want to set the event handler on the repeating panel, e.g.:

self.repeating_panel_1.set_event_handler('x-refresh-tables', self.Func)

And then raise the parent on the repeating panel that’s the parent of the row template, e.g.:

self.parent.raise_event('x-refresh-tables')
3 Likes