Skip to content

Commit 5681118

Browse files
Create Color coded priority fields.js
1 parent 0dc173b commit 5681118

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading || newValue == oldValue) return;
3+
4+
// Mapping backend choice values to background colors
5+
var colorMap = {
6+
'1': '#e74c3c', // Critical - red
7+
'2': '#e67e22', // High - orange
8+
'3': '#f1c40f', // Moderate - yellow
9+
'4': '#3498db', // Low - blue
10+
'5': '#27ae60' // Planning - green
11+
};
12+
13+
// Get control element of the field dynamically
14+
var fieldName = 'priority';
15+
var fieldControl = g_form.getControl(fieldName);
16+
17+
if (!fieldControl) return;
18+
19+
// Reset previous styles before applying a new one
20+
fieldControl.style.backgroundColor = '';
21+
fieldControl.style.transition = 'background-color 0.4s ease'; // smooth effect
22+
23+
// Apply color if matching value found
24+
if (colorMap[newValue]) {
25+
fieldControl.style.backgroundColor = colorMap[newValue];
26+
fieldControl.style.color = '#fff'; // improves text readability
27+
} else {
28+
fieldControl.style.color = ''; // reset if default
29+
}
30+
}

0 commit comments

Comments
 (0)