I did a search and was not able to find it. We have a Spark TextArea with maxChars=”3900″. But it doesn’t work when copy/paste to the text area. I tried to add this to the changingHandler:
if (ta.text.length > 3900)
{
Alert.show("The maximum characters length is 3900. Please limit the characters to the max limit");
ta.text = ta.text.substr(0, 3900);
} else
{
if (event.operation is PasteOperation)
{
....//Other logic
}
}
The problem is it does not work all the time. The Alert shows up only some times when it is over 3900 chars. Not sure why. I also added the same to the changeHandler as well. But that does not get triggered at all.
Please let know what I’m missing. I need to show an alert & trim the chars to the max each time it goes above the max limit.
Thanks
Harish
First, we need to clear one thing: when the changing handler is triggered, that’s means: the text is changing, but the change not apply yet.
if the text in your textare is “”(empty), now, I paste 1600 chars, the changing handler invoked, the length of the text is still 0, because it’s changing, not change.
so now, if you got a change handler, when you trace the length, it should be 1600.
but, if you use “event.preventDefault();” in your changing method, and do nothing to change the text in your changing handler, your change handler should not be triggered.
so, my suggestion is :
if the total lenght is bigger than your limition, you can prevent the event, and do whatever you want to do.
here is some code for you: