How to inherit form controls in Module

What I’m trying to do:
Trying to write some functions in the module under a form

What I’ve tried and what’s not working:

  1. unable to import my top level form inside my module
  2. Trying to create a function to display a content box from any where
  3. How do i refer to an element inside my Form1 from a module

Iam uploading my app structure

Code Sample:
import anvil.server
import anvil.google.auth, anvil.google.drive
from anvil.google.drive import app_files
import anvil.users
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables

This is a module.

You can define variables and functions here, and use them from any form. For example, in a top-level form:

from .Form1 import Module2

Module2.say_hello()

def say_hello():
print(“Hello, world”)

def display_input_box(plc_hldr,titl,min_chars):
txt_box = get_open_form().TextBox(placeholder=plc_hldr)
alert(content=txt_box,title=titl)
if len(txt_box.text.strip())<min_chars:
alert(f"Enter a valid reason not less than {min_chars} Characters…")
return “ERR”
else:
return “OK”

# code snippet

Clone link:
share a copy of your app

Can you please edit your question using Tip on formatting code in posts here? How to ask a good question

It’s also helpful to share a clone link to your app.

1 and 3: You have Form1 set as your startup module. That means it controls the flow when your app starts. If you want to call a function from Module1, you’d probably call that function from Form1 somehow. When you call that function, you can pass the Form (that is, “self,” if you’re calling the Module1 function from within a a Form1 method) to the function as a parameter. Then you can access anything from Form1 that way. Another way to access a form is the get_open_form() function. (See Anvil Docs | Navigation)
2. To trigger an alert, though, you don’t need get_open_form(). TextBox() is not a method of your form. It’s a class that typically gets imported to form code via the “from anvil import *” line.

Thx Tim for the clarification , let me try your suggestion and appreciate your tips on how to post questions…
:+1:

get_open_form() inside the Module1 also worked… :slight_smile: