# Limit selectable values on Dropdown

**URL:** <https://forum.inductiveautomation.com/t/limit-selectable-values-on-dropdown/78804>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [September 6, 2023, 9:36am UTC](https://forum.inductiveautomation.com/t/limit-selectable-values-on-dropdown/78804 "2023-09-06T09:36:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sabhareeswaran\_Ravi](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Sabhareeswaran\_Ravi](https://forum.inductiveautomation.com/u/Sabhareeswaran_Ravi)\
**Post date:** [September 6, 2023, 9:36am UTC](https://forum.inductiveautomation.com/t/limit-selectable-values-on-dropdown/78804/1 "2023-09-06T09:36:42Z")

</div>

Hi,

How to limit the maximum selectable options in dropdown?

For example, The user should be able to select options up to 3 as the maximum.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/b/4b2d2a98756e62ac4df14831e1804c58920a6b1a.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 6, 2023, 10:23am UTC](https://forum.inductiveautomation.com/t/limit-selectable-values-on-dropdown/78804/2 "2023-09-06T10:23:18Z")

</div>

You can add this to an `onActionPerformed` event on the dropdown or to a change script on the `value` property (both should work, though I prefer the event solution):

```python
if self.props.value:
	self.props.value = self.props.value[:3]

```

---

<div class="post-metadata">

**Author:** ![Sabhareeswaran\_Ravi](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Sabhareeswaran\_Ravi](https://forum.inductiveautomation.com/u/Sabhareeswaran_Ravi)\
**Post date:** [September 6, 2023, 10:56am UTC](https://forum.inductiveautomation.com/t/limit-selectable-values-on-dropdown/78804/3 "2023-09-06T10:56:46Z")

</div>

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 6, 2023, 3:04pm UTC](https://forum.inductiveautomation.com/t/limit-selectable-values-on-dropdown/78804/4 "2023-09-06T15:04:56Z")

</div>

Just as a quick note, this doesn't prevent the user from attempting to select additional options - but it will recognize that too many have been selected and remove the "last" selected option.

---

<div class="post-metadata">

**Author:** ![Sabhareeswaran\_Ravi](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Sabhareeswaran\_Ravi](https://forum.inductiveautomation.com/u/Sabhareeswaran_Ravi)\
**Post date:** [September 7, 2023, 6:53am UTC](https://forum.inductiveautomation.com/t/limit-selectable-values-on-dropdown/78804/5 "2023-09-07T06:53:25Z")

</div>

Thanks for the information. What would be the best approach here?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 7, 2023, 4:27pm UTC](https://forum.inductiveautomation.com/t/limit-selectable-values-on-dropdown/78804/6 "2023-09-07T16:27:52Z")

</div>

I do think this is probably a good approach, and shouldn't impact you unless you have expensive bindings based on the selected options.

An Alternate approach is to place a change script on `Dropdown.props.value` which disables any options which are not currently selected if the count of selected options reaches your max.

```auto
# untested pseudo-code
if currentValue and len(currentValue.value) >= 3:
    too_many_so_disable = True
else:
    too_many_so_disable = False
for option in self.props.options:
    if option.value not in currentValue.value:
        option.disabled = too_many_so_disable

```

But keep in mind that this would clobber any custom option disability already in place.
