• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Limit Character Count Solution

Limit Character Count Solution 8 years 8 months ago #35601

  • donaldbmoore
  • donaldbmoore's Avatar
  • OFFLINE
  • Fresh Boarder
  • Where there is a will, there is a way!
  • Posts: 5
I was really surprised, given all the advancements of RSForms, tht there was not native way to limit the character count of a texarea field. After looking through the knowledgebase and forum I found a few useful snippets, but the results didn't always work consistently on a multi-page form. So I just decided to add in a bit more scripting to the examples to get my desired result, I thought I'd share my solution...
What this does:
- Uses the character counter already provided in the documentation
- Hides the next button
- Displays an error message where the next button was located
- Re-displays the button as soon as the character count is corrected
- Removes the error message as soon as the character count is corrected

In order to get these results you must follow these steps:
1. Add in 2 free text fields with the following.
1a. Add "<div id="toolong"></div>" just above your submit or Next Page button (without quotes)
1b. Add "<div><span id="length"></span> Remaining characters (Max 160 )</div>" just above your text field (without quotes, replace with correct number)

2. Add the following to the Additional Attributes field of your textarea field (change 160 to whatever you want the length to be):
onkeyup="rslimitText(160);"
onKeyPress="rslimitText(160);"
onKeyDown="rslimitText(160);"

3. From Form Properties > CSS and Javascript scroll down to Javascript field and paste this in:

<script type="text/javascript">
function rslimitText(limitNum){
document.getElementById('length').innerHTML = limitNum - document.getElementById('metaDescription').value.length;
var msg = "You have reached your maximum limit of characters allowed, you must trim back your description before you can proceed.";
var hideBtn = document.getElementById("homeInfo").classList;

if (document.getElementById('metaDescription').value.length > limitNum) {

document.getElementById('toolong').innerHTML = msg;
hideBtn.add("hidden");

}
else {
hideBtn.remove("hidden");
document.getElementById('toolong').innerHTML = "";

}
}

4. Save your form changes
This worked well for me, I hope it does for you too!
Cindy Moore - mooretechsolutions.com
The administrator has disabled public write access.

Limit Character Count Solution 8 years 2 months ago #36381

  • stan9
  • stan9's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Thanks for taking time to post this. I did my best to follow the instruction but the web site returns a blank page (no form) when the java is inserted in the Form Properties Javascript section. The instructions for the fields seemed to produce normal results. Were there any changes needed for the javascript section?
The administrator has disabled public write access.

Limit Character Count Solution 8 years 2 months ago #36382

Hi Stan9,

I think the ending </script> tag seems to be missing from my post. Could you try that?
The administrator has disabled public write access.

Limit Character Count Solution 8 years 2 months ago #36384

  • stan9
  • stan9's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Thank you so much for your reply. That solved the problem with the whole form displaying blank, but it still doesn't block long text. Are the only changes that need to be made the numbers? Does it matter what the free text fields and the text area field are named?
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!