This content has been marked as final. Show 3 replies
Here is a workaround..
The code below restricts the entry of lines based on the text height.. So you would have to predetermine the text Height based on the number of lines that you prefer to restrict.
if your textfield is multiline (and i assume it is), it makes no sense to restrict to a certain number of lines unless you want to prevent it from needing to scroll. otherwise, make your textfield smaller.
to prevent it from needing to scroll you can use:
Firstly thanks kglad and KnowMind for your responses.
Why I wanted this. I have a textfield that a user fills in. This text is then displayed in another textfield that can't be scrolled at a later point. Therefore I need to limit the number of lines that they use when filling in the first textfield so that it will be fully displayed in the later textfield.
knowmind, your code works, but doesn't do what I wanted. as it increases the size of the textfield being filled out, rather than limitting it.
kglad (as usual) you have done what I wanted, however if a user tries to edit his work, eg, goes back to the top line and clicks enter any line that goes over the height is lost and can't be retrieved, which would be annoying. Therefore instead I am going to use the following code:
remForcedLines = commentTxt.text.split("\r").join(" ");
It simply removes any forced lines that are in textfield 1. Therefore as long as maxChars is under the maxchars in textfield 2, it will display fully. Obviously this wouldn't be particularly practicle for large textfields but as you can see it is only 420 chars long.
So thanks to both of you for your help. J.