Help with changing visible options in dropdown

I currently am making a dropdown list as shown in the image and I have a problem. All of the three dropdowns are used together to know which tags and data to display on a chart below it. The problem I am having is that depending on the first two drop downs will depend on how many tags there are for the third dropdown. For instance, if you do extruder 09 and main extruder, there are 26 different options for tags for that extruder that can be displayed in the chart. However, if you select extruder 09 op extruder there are only 3 tags for that extruder. The issue is that I can’t figure out a way to get only those three tags for the extruder 09 Op extruder to show and have the rest of the 26 options to not show. Basically, I want to change what options are visible for the third dropdown depending on what is selected on the first two dropdowns. I tried to create some sort of binding but I do not now how to make some of the options for the third dropdown disappear depending on the selection for the first two dropdown.

Don’t try to “hide” options. Instead, just always return the correct set of values based on the two inputs.

I made three dropdowns in a row, like your screenshot shows. I then added an “expression structure” binding to the options property of the last dropdown. This expression structure binding will bring in the values from the other two dropdowns automatically - so as soon as either dropdown changes, the expression structure binding will fire again.

Then I added a script transform to build up the list of values based on the conditions.
The better place to contain this data might be a database, but you can also just put everything into the script:

The code is hopefully pretty easy to extend; basically you just check the two incoming conditions (they’re part of the value because of the expression structure binding) and then change your output to suit.

def transform(self, value, quality, timestamp):
	ret = []
	if value["extruder"] == 1:
		if value["type"] == "Main":
			ret.append(1)
			ret.append(2)
			ret.append(3)
		if value["type"] == "OP":
			ret.append(4)
			ret.append(5)
		elif value["type"] == "NOP":
			ret.append(6)
			ret.append(7)
	
	return [
		{
			"value": tag,
			"label": tag
		}
		for tag in ret
	]

In my case, I used the same simple value for the value and label properties that are needed for new dropdown objects. In your case, you may need to have separate value and label fields, so you may need to change the script to accommodate.

Kapture 2022-06-02 at 09.03.02

3 Likes

Very interesting, thank you so much for the detailed and fast response, I just did this and it worked perfectly. Thank you very much!

1 Like