# Disable button/ change color based on tag values

**URL:** <https://forum.inductiveautomation.com/t/disable-button-change-color-based-on-tag-values/87513>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [March 18, 2024, 7:47pm UTC](https://forum.inductiveautomation.com/t/disable-button-change-color-based-on-tag-values/87513 "2024-03-18T19:47:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [March 18, 2024, 7:47pm UTC](https://forum.inductiveautomation.com/t/disable-button-change-color-based-on-tag-values/87513/1 "2024-03-18T19:47:20Z")

</div>

I am trying to make a button that will start a machine, and when the machine is running/while the data is being collected I want the button to be disabled, and to change colors. I have tried to add a change script to the backgroundColor property that looks like this:

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	prgrm = system.tag.readBlocking(['[default]Colder Products Company/Roseville/BurstTester/ProgramNum/Current_Program_Number'])[0].value
	child2 = system.tag.readBlocking(['[default]Colder Products Company/Roseville/BurstTester/Results/Last_Result_Child_2_UID'])[0].value
	lastID = system.tag.readBlocking(['[default]Colder Products Company/Roseville/BurstTester/Results/Last_Result_Unique_ID'])[0].value
	desiredID = system.tag.readBlocking(['[default]Colder Products Company/Roseville/BurstTester/Results/UID_of_Desired_Results'])[0].value
	
	if prgrm == 3 and desiredID == child2 or desiredID == lastID:
		self.props.style.backgroundColor == '#37B117'
	else:
		self.props.style.backgroundColor == '#000000'

```

Does it look like I am on the right track, or am I way off the trail? Any ideas how to make this work?

---

<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:** [March 18, 2024, 8:26pm UTC](https://forum.inductiveautomation.com/t/disable-button-change-color-based-on-tag-values/87513/2 "2024-03-18T20:26:13Z")

</div>

Don't make multiple successive calls with `readBlocking`. The function takes an array/list of tag paths primarily to avoid these types of usages.

```python
tag_paths = [
    	'[default]Colder Products Company/Roseville/BurstTester/ProgramNum/Current_Program_Number'
    	'[default]Colder Products Company/Roseville/BurstTester/Results/Last_Result_Child_2_UID'
    	'[default]Colder Products Company/Roseville/BurstTester/Results/Last_Result_Unique_ID'
    	'[default]Colder Products Company/Roseville/BurstTester/Results/UID_of_Desired_Results'
]
qualified_values = system.tag.readBlocking(tag_paths])
prgrm = qualified_values[0].value
child2 = qualified_values[1].value
lastID = qualified_values[2].value
desiredID = qualified_values[3].value
if prgrm == 3 and desiredID == child2 or desiredID == lastID:
	self.props.style.backgroundColor == '#37B117'
else:
	self.props.style.backgroundColor == '#000000'

```

But... even this isn't a very good approach. This script only executes when a singular value changes. If you're trying to determine a state or appearance based on multiple factors, you need it to update when any of the factors changes value.

Use an Expression Structure binding (and transform) in these scenarios.

 ![Screenshot 2024-03-18 at 1.18.06 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/f/4f80e750863aa6e41e9209e0bd512f783517403b.png)

Note that I'm not modifying the color here - only the enabled state. Use theme files or the stylesheet.css resource to handle styling.

```CSS
/* all buttons */
button.ia_button--primary--disabled,
button.ia_button--secondary--disabled {
	background-color: #000000;
}
/* only buttons with a Perspective Style class ("MyDisabledClass") attached */
button.ia_button--primary--disabled.psc-MyDisabledClass,
button.ia_button--secondary--disabled.psc-MyDisabledClass {
	background-color: #000000;
}
/* only a button with a meta.domId value of MyButton */
#MyButton button.ia_button--primary--disabled,
#MyButton button.ia_button--secondary--disabled {
	background-color: #000000;
}

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 18, 2024, 8:40pm UTC](https://forum.inductiveautomation.com/t/disable-button-change-color-based-on-tag-values/87513/3 "2024-03-18T20:40:16Z")

</div>

What Cody said, but write the logic in a single expression returning a Boolean or a style class name or whatever. That way you avoid the script + transform overhead.
