Dropdown functions

I have two dropdown lists, what i need to happen is when i choose an item on the first dropdown, it will populate the items i enter in the if condition in the second dropdown,

here’s my code

if event.propertyName == "selectedLabel": if event.source.selectedLabel == "Dropdown1": event.source.parent.getComponent('Dropdown2').data("Item1") but i’m getting the error no attribute ‘call’

what am i doing wrong?


When calling getComponent(), it returns an object which exposes the (bindable) properties of a component. So when you called getComponent().data(), you got an error because there is no data() method to perform any actions, the usage for getComponent is supposed to be getComponent().propertyName.

So what exactly are you trying to do, are you copying just the selected value from dropdown1 to dropdown2, or the entire dataset?

Oh i see, what i’m trying to do is, first is i have data on the dropdown 1, the dropdown 2 has no data what i’m trying to do is when I select an item/data in dropdown 1 it will populate data on dropdown 2.
like for example,
dropdown 1

when item1 is selected
dropdown 2 will display

or when item2 is selected it will display

like this.

I believe this is what you’re looking for, this will create two specific datasets, and will copy over the proper dataset based off of item1 or item2 being selected in dropdown1:

[code]headers = [“Value”,“Label”]
data = []
data.append([0, “test1”])
data.append([1, “test2”])

item1_data = system.dataset.toDataSet(headers,data)

data = []
data.append([0, “test3”])
data.append([1, “test4”])

item2_data = system.dataset.toDataSet(headers,data)

if event.propertyName == “selectedLabel”:
if event.source.selectedLabel == “item1”:
event.source.parent.getComponent(‘Dropdown2’).data = item1_data
elif event.source.selectedLabel == “item2”:
event.source.parent.getComponent(‘Dropdown2’).data = item2_data[/code]

this is exactly what i’m looking for. thank you.
last one, how do you .clear a dropdown list in ignition?

You can just create a new dataset with an empty “data” portion:

[code]headers = [“Value”,“Label”]
data = []

new_data = system.dataset.toDataSet(headers,data)
event.source.parent.getComponent(“Dropdown1”).data = new_data[/code]

Or you can just null it out:

event.source.parent.getComponent("Dropdown1").data = None

If you null it out, you will have to create a dataset with headers before performing dataset functions like addRow, updateRow, etc.

Ok got it. Thanks again! :prayer: :thumb_right: :smiley: