Skip to content

Commit c014b15

Browse files
authored
Live Character counter (#2209)
1 parent 6cfa7da commit c014b15

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
This solution dynamically provides users with real-time feedback on the length of a text input field (like short_description or a single-line text variable).
2+
It immediately displays a character count beneath the field and uses visual cues to indicate when a pre-defined character limit has been reached or exceeded.
3+
4+
This is a vital User Experience (UX) enhancement that helps agents and users write concise, actionable information, leading to improved data quality and better integration reliability.
5+
6+
Name Live_Character_Counter_ShortDesc_OnLoad
7+
Table : Custom Table or Incident
8+
Type onChange
9+
Field : Description
10+
UI Type All
11+
Isolate Script false
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
3+
var FIELD_NAME = 'short_description';
4+
var MAX_CHARS = 100;
5+
var currentLength = newValue.length;
6+
var counterId = FIELD_NAME + '_counter_label';
7+
if (typeof g_form.getControl(FIELD_NAME) !== 'undefined' && !document.getElementById(counterId)) {
8+
var controlElement = g_form.getControl(FIELD_NAME);
9+
var counterLabel = document.createElement('div');
10+
counterLabel.setAttribute('id', counterId);
11+
counterLabel.style.fontSize = '85%';
12+
counterLabel.style.marginTop = '2px';
13+
controlElement.parentNode.insertBefore(counterLabel, controlElement.nextSibling);
14+
}
15+
var counterElement = document.getElementById(counterId);
16+
17+
if (counterElement) {
18+
var remaining = MAX_CHARS - currentLength;
19+
20+
21+
counterElement.innerHTML = 'Characters remaining: ' + remaining + ' (Max: ' + MAX_CHARS + ')';
22+
23+
// Apply red color if the limit is exceeded
24+
if (remaining < 0) {
25+
counterElement.style.color = 'red';
26+
} else {
27+
// Revert color if back within limits
28+
counterElement.style.color = 'inherit';
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)