8 Replies Latest reply on Jul 1, 2011 9:54 AM by EduardoDias

    Textarea - Limit content per line

    EduardoDias

      Hello everyone,

       

       

      Is there anyway I can limit the content of a text area per line?

       

       

      For instance, in case an user paste a text which overflow that "predefined" number of line, the textarea will just display the content until the limited value previously set up. Keep in mind that empty lines should be take in count.

       

       

      Any help will be welcome.

       

       

      Thank you very much

        • 1. Re: Textarea - Limit content per line
          _spoboyle Level 4

          do you mean

           

          limit the number of characters on a line

           

          or

           

          limit the number of lines in the textArea?

          • 2. Re: Textarea - Limit content per line
            EduardoDias Level 1

            I mean limit the number of lines in the textArea?

             

            I want limit the lines in a textarea and just allow the user insert content until that specific limit. In case the text have empty lines, it must to be kept.

            • 4. Re: Textarea - Limit content per line
              EduardoDias Level 1

              This is a spark component textarea.

               

              Also, it doens't work in case the user ctrl+c and ctrl+v content inside on it.

              • 5. Re: Textarea - Limit content per line
                _spoboyle Level 4

                you'll still have to subclass textarea and you can implement a similar solution for halo.

                 

                as for copy and paste you should be able to inculde this within your subclass

                • 6. Re: Textarea - Limit content per line
                  EduardoDias Level 1

                  private var moreCharsAllowed:Boolean = true;

                   

                  private var storedInput:String       = "";

                  private var selPos:int               = 0;

                   

                  public function OnepointTextarea():void

                  {

                  super();

                  addEventListener(TextOperationEvent.CHANGE, textChangeHandler, false, 0, true);

                  addEventListener(FlexEvent.CREATION_COMPLETE, initializeData, false, 0, true);

                  }

                   

                   

                  private function initializeData(event:FlexEvent):void

                  {

                  storedInput = textDisplay.text;

                  }

                   

                   

                  override protected function keyDownHandler(event:KeyboardEvent):void

                  {

                  var numLines:uint = textDisplay.mx_internal::textContainerManager.numLines;

                   

                  moreCharsAllowed = (numLines >= maxNumLines)?true:false;

                   

                  storedInput = textDisplay.text;

                   

                  selPos = selectionActivePosition;

                   

                  super.keyDownHandler(event);

                  }

                   

                   

                  private function textChangeHandler(event:TextOperationEvent):void

                  {

                   

                   

                  if(_maxNumLines)

                  {

                   

                  var numLines:uint = textDisplay.mx_internal::textContainerManager.numLines;

                   

                  if(numLines >= maxNumLines + 1)

                  {

                  textDisplay.text = storedInput;

                  textDisplay.selectRange(selPos, selPos);

                  }

                   

                  }

                   

                  }

                   

                   

                  private var _maxNumLines:int;

                  public function get maxNumLines():int

                  {

                  return _maxNumLines;

                  }

                   

                   

                  public function set maxNumLines(value:int):void

                  {

                  _maxNumLines = value;

                  }

                   

                  __________________________________________________________________________________________ ________________________________________

                   

                  But copy and paste still doesnt work

                  • 7. Re: Textarea - Limit content per line
                    kevinklin Adobe Employee

                    Hi,

                     

                    I think what you want is to set the following properties:

                     

                    widthInChars = the width of the textarea in characters.

                    heightInLines = the height of the textarea in lines.

                     

                    then set:

                     

                    maxChars = widthInChars * heightInLines

                     

                    This should limit the number of characters to exactly the size of your text area.

                     

                    -Kevin

                    • 8. Re: Textarea - Limit content per line
                      EduardoDias Level 1

                      Actually, I do not want to limit the number of characters or resize the textarea according to the content. I wanna limit the number of lines.

                       

                       

                      For instance, let's consider the limit for this textarea is 12 lines. The first line can be empty, the second one might be full, the third one might be empty again. The point is, it should never overflow the predefined number of lines, the number of characters is really not relevant.

                       

                      Have a look the screenshot.

                       

                      http://screencast.com/t/Ip6UGN2FI

                       

                       

                      Message was edited by: EduardoDias

                       

                      Message was edited by: EduardoDias