Component problem with DataTable

What I’m trying to do:
I have created a component in a project , added that as a dependency in this app. When i add that component to a form and submit that with an alert() , the server module that writes the row to the db table does not have any of the fields in the component in the dict

What I’ve tried and what’s not working:
Don’t seem to be able to wrap my head around the component properties, the link on the right
is ‘Questionaire’ to invoke this …

Code Sample:

# this is a formatted code snippet.
# paste your code between ``` 

Clone link:
share a copy of your app
https://anvil.works/build#clone:RLHEKZ27BW4V5UWS=OETNSEQERDOLM33N6M45HWPW

thanks for taking a look

I have had a look at your app but there is not information here to be able to understand what you issue.
Might I suggest adding some code snippets / steps (ie which server function etc) to recreate the issue so others in the forum can help.

Sorry , in the navigation on the left side , if you click on the ‘Questionnaire’ link , it will open a form that
has a ‘Custom Component’ at the top , where you can supply name , address , state with three text
area fields below. When i fill out all the fields it doesn’t capture any of the custom component fields
(name, address, state) only the textarea fields get populated in the table ‘questionnaire’. Upon reviewing some posts in the forums regarding ‘custom components - and their setup’ i think this is where i’m lost.

@rickhurlbatt - thanks for taking a look

You have no data binding in your custom component.

image

To get those fields into self.item of the current form, you’d need a property on your custom component you could data bind self.item to, and make sure that that property gets updated as the components change value.

OR, you could not show the default alert buttons, but put buttons on your Feedback form and use self.raise_event('x-close-alert', value=??) where you replace ?? with the dictionary you want returned when they click the Save button. The Cancel button could use self.raise_event('x-close-alert', value=None).

Both ways will work, the second is easier since it doesn’t require messing with custom component properties.

2 Likes

does the self.raise_event(‘x-close-alert’) need a corresponding self.set_event_handler(‘x-close-alert’)
setup ? any attempts i have made to insert this code results in a " ‘value’ is not defined" or something …

The Anvil Docs on “Alerts and Notifications” apparently expects the reader to have 20+ years
of experience coding in python ( or so it seems to me …)

@jshaffstall - this has utterly completely defeated me, i am lost. Would it be possible
(if it only takes you a couple minutes) to whip up a clone link demonstrating how to do this.

If thats asking to much thats ok, i’ll just close the chapter of the “Anvil” book and go pull weeds
from the garden.

Here’s a clone link for a simple example: Anvil | Login

Note that there’s no event handler for x-close-alert, that’s built into the alert itself. You must provide a value argument for it.

Boy was i overcomplicating this … Thank you so much for enlightening me …
i just added :

if result:
#self.label_1.text = str(result)
self.label_1.text = result[‘name’]
anvil.server.call(‘store_vars’, result)

@anvil.server.callable
def store_vars(result):
app_tables.comp_result.add_row(**result)

just what i was looking for
thanks a million …

@jshaffstall - would i be wrong in thinking i can take ( from the project holding your demo link)

Project = “Clone of Forum: Alert with Custom Component and Buttons”

run ‘Use as Component’ on AlertContent form in this project , and then add this project as a dependency into another anvil project , and expect the ‘AlertContent’ custom component to work in the new project as it does here in this project ?

That should work fine. The AlertContent (or whatever custom component you create that works the same) would be usable inside an alert the same.

Indeed it does , thanks again …