View Full Version : restricting characters in a dynamic textfield
regbolD
May 18th, 2009, 09:39 AM
I need to say this, if possible :P
If number of characters in dynamic textfield exceeds 92, find the last word before that limit and put three dots(...) at the end
so, lets say this is the text, and there are 96 characters (I havent been counting but lets imagine it)
IN URNA IPSUM, TINCIDUNT ID, IACULIS QUIS, BIBENDUM PRETIUM, AUGUE. ALIQUAM TEMPOR ALIQUET LOREM. MORBI IN PEDE. ETIAM NEC VELIT. ETIAM EU MI. NAM LIBERO MAURIS, ACCUMSAN ET, DAPIBUS QUIS, CONGUE NON FELIS.
it needs to look like this:
IN URNA IPSUM, TINCIDUNT ID, IACULIS QUIS, BIBENDUM PRETIUM, AUGUE. ALIQUAM TEMPOR ALIQUET LOREM. MORBI IN PEDE. ETIAM NEC VELIT. ETIAM EU MI. NAM LIBERO MAURIS, ACCUMSAN ET, DAPIBUS QUIS, CONGUE NON...
possible?
cbeech
May 18th, 2009, 10:09 AM
certainly ;)
var originalText = [as above];
var subText = originalText.slice(0, originalText.lastIndexOf(' ', 92)) + '...';
regbolD
May 18th, 2009, 12:53 PM
ok, it works partially, in my case :P
my problem is this:
I have a textfiled fixed width, and 4 rows of text height (so actually both width and height are defined).
(and I have counted that 92 characters fit into this 4 lines of that textfield)
but if I say this:
topic_txt.autoSize=TextFieldAutoSize.LEFT;
textfield height will get streched if there is more text.
but the problem is that (long) words skip into new line and thus all empty spaces dont get count into that 92 characters... so actually some text that is not 92 characters long sometimes makes 5 lines of text... if the words skip into new line how come all empty spaces arent counted as characters?
cbeech
May 18th, 2009, 01:56 PM
hmmm - most likely the issue is the autoSize prop - try removing that, leave the field as a static size and see what happens.
regbolD
May 18th, 2009, 02:22 PM
I tried and these are the results, and as you can see sometimes I get 5 lines of text which are not 92 characters long, and if I dont set the autoSize, I will have 4 lines but text wont get (...) on the end, which is not the end of the world, but still not as I planned.
I dont understand, I counted that in 4 lines of text fits 92 characters, so how come it makes 5 lines without passing that limit?
empty spaces are counted, arent they?
then whats the problem then?
http://img98.imageshack.us/img98/3936/22895855.jpg
can you say?
make 4 lines of text, plus (...) at the end of last word
cbeech
May 18th, 2009, 04:19 PM
okay :) well i had to give this a try lol - and it seems to be operating as expected with one adjustment - since were 'adding' 3 characters to the text (ie. '...') i used a value of 89 rather than 92 - this cuts off the string previous to the 92 char limit and finds the word break prvious to that point.
in the example you have it seems apparent that not to use autoSize, it will be a matter of calibrating the string, and since word lengths vary, you just need to find the right number - which i think may be 89 :)
here is a simple example doc for you to mess around with :D
regbolD
May 18th, 2009, 04:32 PM
89 you think?
are you sure this is going to work... :P
because if I figured it out correctly its all due to how the words not fitting into current line are being skipped into next line and you cant predict how words are going to look :D
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.