Hi I have been through a few tutorials and am trying my first app. I’ve been struggling with something that seems like you shjould be able tyo do but can’t find examples in docs or forums. I’m getting quite discouraged as I thought I had a basic grasp of this and only really slightly extending on the News aggregator example.
I am trying to create an “add staff form”. It will eventually have all the usual fields you would expect. I decided it might be clever (and I would learn a good pattern) if I made the address as a nested form so that I might re-use it to input addresses unrelated to staff in other parts of the app (I know, “don’t build it till you need it”, but I am just trying to learn concepts).
I created am AddressEdit form with 3 text fields
- unit
- street_num
- street_name
when I tried data binding the fields e.g. self[‘unit’] I got and error about " Did you initialise all data binding sources before initialising this component?"
I created a “StaffEdit” form with 2 text fields and 1 field which is the AddressEdit form (I dragged the AddressEdit form onto the design page UI for my StaffEdit form.)
- surname (data binding self[‘surname’] )
- first_name (data binding self[‘first_name’] )
- addressedit (form, tried data binding but don’t know what i’m doing)
I have gone round many circles using (or not) data bindings etc. and trying different scenarios to get this so I can’t say everything I have tried in detail or paste exact code. I am using the same pattern from the News Aggregator app with the alert popup and “if save_clicked…”
Code Sample:
def add_staff_button_click(self, **event_args):
"""This method is called when the button is clicked"""
new_staff = {}
save_clicked = alert(
content=StaffEdit(item=new_staff),
title="Add Staff",
large=True,
buttons=[("Save", True), ("Cancel", False)]
)
# If the alert returned 'True', the save button was clicked.
if save_clicked:
print(new_staff)
When the print statement runs I just get the surname and first name back. I believe at one stage I had a version where it returned an addressedit object as new_staff['address']
but I don’t remember what state the code was in when it got that far and it’s no longer working.
Am I even approaching this the right way? Is this a stupid idea? Should you be able to access the nested forms fields by using self.item of the parent field?
I would like to use the data from the address form to add to an addresses data table and the other info to populate the staff data table (with has a table link to the address table).