What I’m trying to do:
I am trying to create UI by creating a pop up form for my users to fill out. And once I click on save, the data to be saved in my data base.
What I’ve tried and what’s not working:
I am getting this error and I do NOT understand why.
AttributeError: 'Event' object has no attribute 'key'
at app/m3/_Components/TextInput/TextBox.py:149
Client Side Code:
from ._anvil_designer import HomeTemplate
from anvil import *
import anvil.server
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
from .Company_Info_Form import Company_Info_Form
class Home(HomeTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run before the form opens.
def button_1_click(self, **event_args):
"""This method is called when the component is clicked."""
company_info_form = Company_Info_Form()
def save_action():
anvil.server.call('save_company_info', Company_Info_Form.get_data())
return True
alert(
content=company_info_form,
large=True,
buttons=[("Save", save_action), ("Cancel", False)]
)
pass
Server Side Code
@anvil.server.callable
def save_company_info(data):
"""
Save company information using data passed as a dictionary.
"""
# Extract data from the dictionary
app_tables.move_company.add_row(
Company_ID=data.get('company_id'),
Company_Name=data.get('company_name'),
Email=data.get('email'),
Phone_Number=data.get('phone_number'),
Website=data.get('website'),
Address=data.get('address'),
License=data.get('license'),
Service_Area=data.get('service_area')
)
Company_Info_Form
class Company_Info_Form(Company_Info_FormTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run before the form opens.
data = {
'company_id': self.text_box_company_id.text,
'company_name': self.text_box_company_name.text,
'contact_name': self.text_box_contact_name.text,
'email': self.text_box_email.text,
'phone_number': self.text_box_phone_number.text,
'website': self.text_box_website.text,
'address': self.text_box_address.text,
'license': self.text_box_license.text,
'service_area': self.text_box_service_area.text
}
Clone link:
share a copy of your app