Can onclick in app A call seperate onlick method in app B?

I imagine this is possible, but I’m not sure how…

https://anvil.works/build#clone:OJ3K7HOD3X27PWFK=IRZSC4BQ3PSFXOI3HGQBD5GD
App1 ^
In App1, I have a form (Form1), with a link (link_1)
In App1, there is a dependency on custom_signup app which is linked below v
https://anvil.works/build#clone:GHYFKQOFMOPHPT5Q=E5YFEN4KUT6G3ET7YJLMHSE7

This custom_signup app has a form called Splash, with an onlick handler for a button called login_btn_click

Here’s what I’m trying to do…
In App1, I’d like the onlick event for link_1 to call and execute the onlick code login_btn_click

Is this possible?

If you have imported your dependency into App 1, can you simply call the dependency’s function from within inside App 1’s link callback? (Or raise the desired event)?

Thanks for sharing the clones but what have you tried to do and what error are you receiving? (Perhaps that is given in the clones, but I’m on my cell at the moment).

Let me know if I’m misunderstanding the question. It souns like you want to execute a function and/or raise an event inside a dependency.

Here’s my attempt to show what I’m doing…

As you can see, I’m trying to call the “login_btnclick” method inside of the “link_1_click” method. When I click link_1, I get an error indicating
“login_btn_click is not defined”

Just a reminder, “login_btn_click” is a method that lives in the “Splash” form. The “Splash” form resides in the dependent app.

Not sure how to go from here

I can’t test it right now, but my guess is that you should be able to use the usual dot notation to access methods on that dependency. When you inspect the dependency class, does the autocompleter give you any hints as to how to interact with it? As I said, I’m away from the computer so I can’t be more specific. I’m sure I’ve done this before though.

It’s probably worth looking at the first few minutes of this video https://anvil.works/docs/how-to/custom-user-auth where the login flow module is used which I think will answer your question.

  • You also would need the users, datatables service in your App1 for the login flow module to work.

It does, but only for using code from server modules. How do you import and use Form code?

I don’t think it makes sense to have your Splash form inside the custom_signup dependency. This wants to be part of the main app no?

Notice how in the Splash Form you’re just importing the login_flow module so you could do the same here… like this

from custom_signup import login_flow 

Then do similar things to what you did in your Splash Form

Alternatively if want to use the Splash Form you have to do something like

from custom_signup.Splash import Splash
...
# initiate the Splash Form somewhere
self.splash = Splash()
...

def link_1_click(self, **event_args): 
  self.splash.login_btn_click()

But it doesn’t seem best practice.
Do note that you’ll need the users table in your main app for this to work.

Personally I would do:

from custom_signup import login_flow

def link_1_click(self, **event_args): 
  login_flow.login_with_form()

or something… again making sure to have the users table in your main app.