"""This method is called when the button is clicked"""
anvil.server.call(
'add_contactno',
contactno=self.text_box_contactno.text,
link_clients_name=self.drop_down_linktoclient.selected_value,
)
When you’re adding a row that contains a linked field, you need to give the entire linked row as the value for that field, not just a portion of it. In your case you’re giving it just the client name, not the entire client row.
To fix it, you’d want to use the alternate form for populating the dropdown items where you give each item both a visible value and the real value. See this section of the docs for how to do that: Anvil Docs | Dropdowns and Data Tables
After you’ve done that, when you get the selected value from the dropdown you’ll be getting the entire row, not just the name. From there everything else should work.
okay that worked
but now this code does “invalid value” in dropdown after saving
self.drop_down_linktoclient.selected_value =self.drop_down_linktoclient.items[0]
The selected_value property must be set to a valid value (e.g. the second part of the tuple for an item). You’re setting it to the entire tuple. Something like this should work to pull just the value out of the tuple:
There is no None value in a dropdown by default. If you want there to be a blank value that you can use with a None value, you need to add that to the items list yourself. In your clients module you can do that after you sort the list:
That has nothing to do with the dropdown. In your clientno data table you have a bad row at the end that has a None value for the linked row. Delete that row so that your data bindings (which expect the linked field to not be None) work.
To get your dropdown to be blank after clicking the add button, uncomment line 19 in your clients module and then use self.drop_down_linktoclient.selected_value = None to clear the dropdown value.
The dropdown will go through each element of whatever you pass it and create an entry in the dropdown for each element. You’ve set the items property of a dropdown to a string. Each element of the string is a character, so each entry in the dropdown is a single character.
If you want the dropdown to have all the names then you should set it’s items property the same way you did for the outside one, as clients.names. You won’t be able to do that in a data binding, but you can do that in the __init__ of your repeating row template form.