From 7fb0809de0a891962128787bddf2393e565d42a3 Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Fri, 10 Oct 2025 14:55:29 +0530 Subject: [PATCH 1/8] Create Real-Time Character Counter for Text Fields Add a script that shows a live character count below a text field (e.g., Description or Comments) as the user types. If the user exceeds a limit (say 500 characters), display a warning and optionally disable the submit button. --- .../Real-Time Character Counter for Text Fields | 1 + 1 file changed, 1 insertion(+) create mode 100644 Client-Side Components/Catalog Client Script/Real-Time Character Counter for Text Fields diff --git a/Client-Side Components/Catalog Client Script/Real-Time Character Counter for Text Fields b/Client-Side Components/Catalog Client Script/Real-Time Character Counter for Text Fields new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Real-Time Character Counter for Text Fields @@ -0,0 +1 @@ + From fb235849e219aba9d99589606ad3e54d484c390a Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:11:04 +0530 Subject: [PATCH 2/8] Rename Real-Time Character Counter for Text Fields to Real --- .../{Real-Time Character Counter for Text Fields => Real} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Client-Side Components/Catalog Client Script/{Real-Time Character Counter for Text Fields => Real} (100%) diff --git a/Client-Side Components/Catalog Client Script/Real-Time Character Counter for Text Fields b/Client-Side Components/Catalog Client Script/Real similarity index 100% rename from Client-Side Components/Catalog Client Script/Real-Time Character Counter for Text Fields rename to Client-Side Components/Catalog Client Script/Real From 9b07308ec9e60f08525e10b229a7279506bd77b7 Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:11:58 +0530 Subject: [PATCH 3/8] Update and rename Client-Side Components/Catalog Client Script/Real to Client-Side Components/Catalog Client Script/Real time count of letters/readme.md --- Client-Side Components/Catalog Client Script/Real | 1 - .../Catalog Client Script/Real time count of letters/readme.md | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 Client-Side Components/Catalog Client Script/Real create mode 100644 Client-Side Components/Catalog Client Script/Real time count of letters/readme.md diff --git a/Client-Side Components/Catalog Client Script/Real b/Client-Side Components/Catalog Client Script/Real deleted file mode 100644 index 8b13789179..0000000000 --- a/Client-Side Components/Catalog Client Script/Real +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Client-Side Components/Catalog Client Script/Real time count of letters/readme.md b/Client-Side Components/Catalog Client Script/Real time count of letters/readme.md new file mode 100644 index 0000000000..064c4dfb0e --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Real time count of letters/readme.md @@ -0,0 +1,2 @@ + +Add a script that shows a live character count below a text field (e.g., Description or Comments) as the user types. If the user exceeds a limit (say 500 characters), display a warning and optionally disable the submit button. From ca8fb4f382cb36173507b368d0bf18a519a32949 Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:12:59 +0530 Subject: [PATCH 4/8] Create Count letters.js --- .../Real time count of letters/Count letters.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js diff --git a/Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js b/Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js @@ -0,0 +1 @@ +test From 0e7b04ef131e0a0753b8970ea7e89a9c3d87c0e1 Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:13:48 +0530 Subject: [PATCH 5/8] Update readme.md --- .../Catalog Client Script/Real time count of letters/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client-Side Components/Catalog Client Script/Real time count of letters/readme.md b/Client-Side Components/Catalog Client Script/Real time count of letters/readme.md index 064c4dfb0e..d91653bd04 100644 --- a/Client-Side Components/Catalog Client Script/Real time count of letters/readme.md +++ b/Client-Side Components/Catalog Client Script/Real time count of letters/readme.md @@ -1,2 +1,2 @@ -Add a script that shows a live character count below a text field (e.g., Description or Comments) as the user types. If the user exceeds a limit (say 500 characters), display a warning and optionally disable the submit button. +Script that shows a live character count below a text field (e.g., Description or Comments) as the user types. If the user exceeds a limit (say 500 characters), display a warning and optionally disable the submit button. From 24c770f3733870e6bde335e538d61ef0754fa499 Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:14:33 +0530 Subject: [PATCH 6/8] Update Count letters.js --- .../Count letters.js | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js b/Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js index 9daeafb986..af3f17fa94 100644 --- a/Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js +++ b/Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js @@ -1 +1,34 @@ -test +(function executeRule(current, g_form, g_user, g_scratchpad) { + var fieldName = 'short_description'; // Change to your field name + var maxChars = 500; + + // Create a span element for character count + var charCounterId = 'char-counter-' + fieldName; + if (!document.getElementById(charCounterId)) { + var counterSpan = document.createElement('span'); + counterSpan.id = charCounterId; + counterSpan.style.fontSize = '12px'; + counterSpan.style.color = '#555'; + var fieldElement = g_form.getControl(fieldName); + fieldElement.parentNode.appendChild(counterSpan); + } + + // Update character count on keyup + var fieldElement = g_form.getControl(fieldName); + fieldElement.addEventListener('keyup', function () { + var currentLength = fieldElement.value.length; + var counterSpan = document.getElementById(charCounterId); + counterSpan.textContent = currentLength + ' / ' + maxChars + ' characters'; + + // Show warning if limit exceeded + if (currentLength > maxChars) { + counterSpan.style.color = 'red'; + g_form.addErrorMessage('Character limit exceeded! Please shorten your text.'); + g_form.setSubmit(false); // Block submit + } else { + counterSpan.style.color = '#555'; + g_form.clearMessages(); + g_form.setSubmit(true); + } + }); +})(current, g_form, g_user, g_scratchpad); From b5f766983fed65666e5a2fd79424b6ddaa8b0b5a Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:33:01 +0530 Subject: [PATCH 7/8] Update Count letters.js --- .../Count letters.js | 54 ++++++++----------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js b/Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js index af3f17fa94..71a6a70f0e 100644 --- a/Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js +++ b/Client-Side Components/Catalog Client Script/Real time count of letters/Count letters.js @@ -1,34 +1,26 @@ -(function executeRule(current, g_form, g_user, g_scratchpad) { - var fieldName = 'short_description'; // Change to your field name - var maxChars = 500; - - // Create a span element for character count - var charCounterId = 'char-counter-' + fieldName; - if (!document.getElementById(charCounterId)) { - var counterSpan = document.createElement('span'); - counterSpan.id = charCounterId; - counterSpan.style.fontSize = '12px'; - counterSpan.style.color = '#555'; - var fieldElement = g_form.getControl(fieldName); - fieldElement.parentNode.appendChild(counterSpan); +function onChange(control, oldValue, newValue, isLoading) { + if (isLoading) { + return; } - // Update character count on keyup - var fieldElement = g_form.getControl(fieldName); - fieldElement.addEventListener('keyup', function () { - var currentLength = fieldElement.value.length; - var counterSpan = document.getElementById(charCounterId); - counterSpan.textContent = currentLength + ' / ' + maxChars + ' characters'; + var maxChars = 100;//count of charaters + var currentLength = newValue.length; + + // Clear previous messages + g_form.clearMessages(); + + // Show info message + g_form.addInfoMessage('Character count: ' + currentLength + ' / ' + maxChars); - // Show warning if limit exceeded - if (currentLength > maxChars) { - counterSpan.style.color = 'red'; - g_form.addErrorMessage('Character limit exceeded! Please shorten your text.'); - g_form.setSubmit(false); // Block submit - } else { - counterSpan.style.color = '#555'; - g_form.clearMessages(); - g_form.setSubmit(true); - } - }); -})(current, g_form, g_user, g_scratchpad); + if (currentLength > maxChars) { + // Show error message + g_form.addErrorMessage('Character limit exceeded! Please shorten your text.'); + g_form.showFieldMsg('short_description', 'Too many characters!', 'error'); + + // Make field mandatory to block submission + g_form.setMandatory('short_description', true); + } else { + // Remove mandatory if valid + g_form.setMandatory('short_description', false); + } +} From 5b79a1c61b12293a328e0662d256a35853904b23 Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:34:08 +0530 Subject: [PATCH 8/8] Update readme.md --- .../Catalog Client Script/Real time count of letters/readme.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Client-Side Components/Catalog Client Script/Real time count of letters/readme.md b/Client-Side Components/Catalog Client Script/Real time count of letters/readme.md index d91653bd04..668903071b 100644 --- a/Client-Side Components/Catalog Client Script/Real time count of letters/readme.md +++ b/Client-Side Components/Catalog Client Script/Real time count of letters/readme.md @@ -1,2 +1 @@ - -Script that shows a live character count below a text field (e.g., Description or Comments) as the user types. If the user exceeds a limit (say 500 characters), display a warning and optionally disable the submit button. +This onChange Catalog Client Script displays the current character count for a text field and enforces a maximum limit by showing error messages and making the field mandatory to prevent form submission when exceeded.