So if I have say a button that is a part of a repeating panel and I want to give users the option when this button is clicked that it opens up a form I have created called UpdateFeed for example and in there are some fields like the snake name, date fed, etc that I want to populate from where the record button was clicked.
Is there anyway to do this with an alertbox so I can call the form with some type of input that the form can use for my items on the page or how might this work?
I have a similiar delete option working but that isn’t using a alert box it instead is just looking up that record and then removing it, the tricky part here I’m getting confused on is how to trigger the content to be a form with data populated from where the button was clicked.
Let me know if this is confusing. Normally on my add record page for example the init loads these values up from the list, in this case I want to pass it the snake name and date fed which I know about from where this button is clicked.
def update_feed_btn_click(self, **event_args):
"""This method is called when the button is clicked"""
result = alert(content=UpdateFeed(),
large=True,
buttons=[
("Change", "change", "success"),
("Discard", "discard", "danger")
])
print("User chose: {}".format(result))
What I’ve been doing in similar situations is passing the id of the record into the form. So in yours, it might be something like:
alert(content=UpdateFeed(self.item['id'])
Or whatever identifies the record for your item. Or you can pass the entire row in, whatever works for you. Then in UpdateFeed you access that parameter in the init:
def __init__(self, item_id, **properties):
The item_id corresponds to the value self.item[‘id’] from the call.
1 Like
Oh cool wasn’t sure if you could do that, thanks!
Do you happen to know where the values I have in that form can be accessed when say someone hits the change button I have configured in the alert? The goal was if they changed an item in the popup and then hit change I would take those values and update the record basically.
Wasn’t sure if this should be written in the form that the alert pops up or where I call the alert from.
I change them in the form itself. I don’t use the built in alert buttons, I put buttons on the embedded form, and then it’s no different from if the form wasn’t embedded. The code all runs in the same form, where you can do self.text_field_1.text and so on.
@jshaffstall solution works just fine, but you can also do something like this:
f = Form2()
pressed_button = alert(f)
print pressed_button
print f.text_box_1.text
2 Likes
This was really handy I went with this option I completely forgot about doing it like that.
This is pretty slick cause now they just change the values and hit change and the server call handles the rest.
Thanks for the suggestion @stefano.menci