Home
TeamSite
Character Count progress in Textarea
Team
Does anyone know a Solution for the problem described below?
1. I have a textarea with character limit of 500 character. I want a status bar or something which will continously display how many character are left.
e.g: if a user is entering characters in textbox - it should simultaneoulsy update that you have this much characters left out of 500.
I tried to implement this with the following code as below. It did work but the PROBLEM is that it updates the character count when you leave the textarea.
is there something that could work when the textarea is in Focus only rather then moving out of the textbox? Right now - i have added additional texbox which will display no of character the user entered in textarea.
Code:
<script>
<![CDATA[
<!-- ===== TEXTAREA CHAR PROGRESS ==== -->
IWEventRegistry.addItemHandler("/CATEGORY_COMPACT_DESCRIPTION", "onItemChange",
itemProgress);
var textitem = IWDatacapture.getItem("/CATEGORY_COMPACT_DESCRIPTION");
var maxLimit = "500";
var thepathid = "";
var thename="";
function itemProgress(textitem)
{
<!-- if (textitem.getValue() == "") {-->
alert("I will start counting Characters!");
<!-- textitem.setValue(textitem.oldValue);-->
textitem.setValue(textitem.getValue());
alert("Characters you entered : "+ textitem.getValue());
displaylimit();
<!-- } -->
function displaylimit(thename, pathid, thelimit)
{
alert("I have enter counting function");
<!--IWDatacapture.getItem("/charCount").setValue(textitem.getValue());-->
var charcnt = textitem.getValue().length;
IWDatacapture.getItem("/charCount").setValue(charcnt);
alert("No of characters are "+ charcnt);
}
}
<!-- ==== CODE ENDS ==== -->
]]>
</script>
Find more posts tagged with
Comments
JonathonG
Without somehow hacking in to the backend of the code generated by TeamSite, I don't believe there is any way to do what you want. onItemChange events for textareas only get fired as focus leaves the control (per IWOV FormAPI documentation). So, I don't see any way to create a status bar that continuously updates. If you wanted to try and hack in (not recommended nor supported), what you would actually need is onKeyDown/onKeyUp events, as well as onFocus/onBlur events, and some fairly sophisticated logic for handling new characters. Is this a demand from your business client or a "nice to have"? I would suggest that as a "nice to have", it would qualify for the "not gonna do it" category. As a demand from your client, I would suggest that it belongs to the "tell them its gonna cost a bunch" category.
Jonathon
Interwoven Developer
Allstate, Inc.
Team
It could be anything - may be a textarea which is updating number of characters left, not necessary a status bar. i have seen JS functions like - OnKeyUp/OnKeyPress or OnFocus not so flexible with the DCT. Is there anything which can internally keep calling the JS count function and keep updating the textarea?
Right now i have this functionality working which updates in another textarea but only once the Focus is out of that textarea on which i am counting the characters.
Its a Business requirement. If there is something that could resolve this issue, it will be great.
Adam Stoller
As JG said - FormAPI doesn't [natively] support what you want to do.
Your choices are
- hack the code by going outside (or inside, depending on your view point) the API and using basic JS functionality to somehow track the keyboard events
- file a feature request through IWOV Support
The latter *may* lead to a work-around solution, but most likely it will be logged and will have to wait for IWOV Product Management / Engineering to take a look into what it would take to implement it and then get the approval to do so (i.e. not likely to happen in the next month, possibly not in 6 months). Your customer needs to be made aware of the filing of the request and the feedback - and they can try to encourage IWOV to do something about it more quickly - however, as features goes - this doesn't sound like critical-path (a very nice feature perhaps, but not crucial to being able to use the product)
The after-the-fact verification can be used to alert the user of having gone beyond the allowed range and marking the item as invalid to prevent saving it with extra data.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
jbonifaci
Another option, which wouldn't be considered a hack, but would be somewhat ugly, would be to have a cgi-callout for this field where you will have complete control of the window. If the user wants to track their progress, they click on the "Input with tracker" option, or whatever you call it. This would open up a small window with only a textarea and your character counter. The user would still be able to edit text directly in the DCT without the counter, but both options would be available.
Not a clean solution from a UI or UE perspective, but one that doesn't require any "hacking".
~Jeff