# Dropdown Selected Label (Value Label)

**URL:** <https://forum.inductiveautomation.com/t/dropdown-selected-label-value-label/69112>\
**Category:** Ignition\
**Tags:** ignition81, vision, perspective\
**Created:** [January 27, 2023, 8:44pm UTC](https://forum.inductiveautomation.com/t/dropdown-selected-label-value-label/69112 "2023-01-27T20:44:10Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [January 30, 2023, 2:16pm UTC](https://forum.inductiveautomation.com/t/dropdown-selected-label-value-label/69112/6 "2023-01-30T14:16:27Z")

</div>

For those looking to do the same thing, I added 3 custom props to the dropdown.

1. `selected_value` - bound directly to the `value` prop of the dropdown  
a. Use a value change script to loop through the array of options and update the index and label.
2. `selected_index` - updated from change script
3. `selected_label` - updated from change script

change script:

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):

	val = currentValue.value
	if val is not None:
		count = len(self.props.options)
		for item in range(0, count):
			if self.props.options[item].value == val:
				self.custom.selected_index = item
				self.custom.selected_label = self.props.options[item].label
	else:
		self.custom.selected_index = None
		self.custom.selected_label = None

```

My reason for wanting to do this was to add buttons that would go to the next or previous item in the list. Fairly easy with scripts with the `selected_index` property.

next:

```auto
def runAction(self, event):
	
	current = self.getSibling('Dropdown').custom.selected_index
	maxIndex = len(self.getSibling('Dropdown').props.options)-1
	if current < maxIndex:
		next = current + 1
	else:
		next = 0
	
	self.getSibling('Dropdown').props.value = self.getSibling('Dropdown').props.options[next].value

```

previous:

```auto
def runAction(self, event):

	current = self.getSibling('Dropdown').custom.selected_index
	maxIndex = len(self.getSibling('Dropdown').props.options)-1
	if current > 0:
		next = current - 1
	else:
		next = maxIndex
	
	self.getSibling('Dropdown').props.value = self.getSibling('Dropdown').props.options[next].value

```

The `enabled` prop for each button is bound to the dropdown. If the value is null, the button is disabled.

---

_[View the full topic](https://forum.inductiveautomation.com/t/dropdown-selected-label-value-label/69112)._
