0
votes

If I give restrict="[a-z][A-Z]" in a spark TextArea, and paste content into it, all the line breaks are stripped. Manually pressing enter works fine. Where is the problem?

<s:TextArea restrict="[A-Z][a-z]"/>

The mx TextArea works fine.

2
Try adding paste event to your textArea and check what paste event says. - Jarno Lahtinen

2 Answers

0
votes

Line breaks won't work if you restrict it. Try doing this:

<s:TextArea restrict="A-Za-z\n"/>
0
votes
protected function textArea_changingHandler(event:TextOperationEvent):void
        {
            if (event.operation is PasteOperation)
            {
                event.preventDefault();
                var txt:String = Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT).
                    toString().replace(/[^A-Za-z0-9\s]/ig, "");
                var curPos1:Number = textArea.selectionAnchorPosition;
                var curPos2:Number = textArea.selectionActivePosition;
                if (curPos2 < curPos1)
                {
                    var t:Number = curPos1;
                    curPos1 = curPos2;
                    curPos2 = t;
                }

                if (textArea.text.length > 0)
                {
                    textArea.text = textArea.text.substr(0, curPos1) + txt + textArea.text.substr(curPos2, textArea.
                        text.length);
                }
                else
                {
                    textArea.text = txt;
                }
                textArea.selectRange(curPos1 + txt.length, curPos1 + txt.length);
                event.preventDefault();
            }
        }

This effectively takes care of all scenarios/ operations that can occur during paste.