Access function from a different form

I have a form with a data table and plot and ‘refresh_plot’ function.

In another form (row template) I have a delete button and when it’s pressed I need the ‘refresh_plot’ function to be called on the first form.

Anyone offer any help?

Hello,

If the desired function is in your main form, you can “reach back” and call it from anywhere with get_open_form().my_function(). In general, you can also store functions that you want to use on a component (e.g., the tag property). All that is needed is a way to access them from any other form.

Here are some good tips that are related to this technique:

1 Like

It’s tricky because like you say get_open_form() gives me main as I opened the form in the content panel.

You could use similar techniques though in various ways. In general, to call functions that exist elsewhere, you can try the following:

  • you could store the form that has the desired function on the main form (see here)

  • you could store your function in a module

  • you could store your function on a component (that you can access)

  • you can use parent to access the parent form (though this is not always a great approach)

  • you could pass an instance of form to another form (and thus have access to its functions)

The linked post also has a bunch of related links that deal with the same issue. Please have a read.

1 Like

Thanks a lot, sorted it with your the first bullet point.

1 Like