Hi,
I am trying to add a repeating panel button text to a drop-down list, but is not working for me, can you please help?
https://anvil.works/build#clone:R2B7QYW6W4ZSQ7OD=RZ7IPSHJ7OQ24HGJJNFCNZZF
Hi,
I am trying to add a repeating panel button text to a drop-down list, but is not working for me, can you please help?
https://anvil.works/build#clone:R2B7QYW6W4ZSQ7OD=RZ7IPSHJ7OQ24HGJJNFCNZZF
Hi @adhamfaisal,
This is a very general question! If you post something like “I’m trying to do [something], but it’s not working for me”, then anyone who wants to help you has to do a lot of work! They have to guess what you’re trying to do, then open your app, find where the problem lies, and then suggest a solution.
If you want to make it more likely that someone will help you, here are some hints. When posting on this forum, please try to:
Be specific about what you’re trying to do.
For example:
I want to add a new option to a DropDown’s
items
when you click a button in a RepeatingPanel.
Be specific about what’s not working, and what you’ve tried already.
For example:
I’ve written code in my
ItemTemplate
’s button-click handler, which updates the DropDown onForm1
. But when I click the button the DropDown doesn’t get updated. I know thebutton_1_click
function is running without errors, because I’ve tried putting aprint()
statement there – when I do that, and click the button, it prints in the Output panel. But it doesn’t seem to change the DropDown.
Maybe include a code sample of the relevant code. (In case this code isn’t enough for people to work out what’s going wrong, it’s also helpful to include a clone link for your app. You did this in your post, which is good! It’s even better if you give instructions so someone can reproduce the problem once they’ve copied the app.)
For example:
Here’s the button-click handler from my ItemTemplate1 form:
def button_1_click(self, **event_args): """This method is called when the button is clicked""" text = self.button_1.text items = Form1.Form1().drop_down_1.items items = items + [text]
If you want to look at the whole app, here it is:
Anvil | Login
To reproduce the error, hit Run and then click any of the buttons, then check the DropDown. You should see extra options appearing, but you don’t. Can anyone help?
If you ask questions like this, then it’s much easier for us to help you – and this means it’s much more likely that you’ll get help!
For example, now that I’ve restated your problem in an easy-to-understand way, I expect one of our forum regulars will be able to answer your question before long…
Thank you Meredydd for the tips
Ok …
for starters, you are not reassigning the items to the drop down. You update your local variable `items but that won’t change the drop down.
Next, I don’t think you are working on your actual displayed Form1. I think you are creating a new one.
Instead, do this :
(edited for comments)
# Create a reference to the drop down for convenience.
# get_open_form() will reference the last form opened either with "open_form"
# or your initial form when the app starts.
dd_object = get_open_form().drop_down_1
items = dd_object.items
# Note here that your "text" value was numeric, so you need to convert it
# to a string.
items = items + [str(text)]
# Now reassign the updated items to the drop down.
dd_object.items = items
That should work, I think.
Thank you , That was very helpful!