I figured it out. Turns out the TextArea (TextField) does respond to the restrict when text is pasted into it. However, the way the restrict works is dependent on how you specify it -- mxml vs actionscript. If I do
<mx:TextArea id="test" restrict="\u0009\-A-Z0-9" /> it won't accept the tab but strips out all the unwanted characters. If, on creationComplete, I do test.restrict="\u0009\\-A-Z0-9" it accepts the tab character and strips out all the unwanted characters. Sigh. ----- Original Message ----- From: Dave Bonnell To: [email protected] Sent: Friday, June 11, 2010 4:41 AM Subject: [flexcoders] Re: TextArea -- allow tab character in restrict property The problem is that the Flash TextField control does not seem to apply the restrict when text is pasted into the field. TextField dispatches a textInput event whenever text is typed or pasted, so by intercepting this, you can manually apply the restrict yourself. <?xml version="1.0" encoding="utf-8"?> <mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml" textInput="textInput_handler(event)" keyFocusChange="keyFocusChange_handler(event)"> <mx:Script> <![CDATA[ private var restrictPattern : RegExp; // cached RegExp for matching characters NOT in restrict private var tabAllowed : Boolean = false; // flag indicating if restrict contains the TAB character override public function set restrict( value : String ) : void { if ( value == null ) { restrictPattern = null; tabAllowed = false; } else { restrictPattern = new RegExp( "[^" + value + "]", "g" ); tabAllowed = ( value.indexOf( "\\t" ) != -1 ); } super.restrict = value; } override public function set text( value : String ) : void { if ( restrictPattern ) value = value.replace( restrictPattern, "" ); super.text = value; } private function textInput_handler( event : TextEvent ) : void { if ( restrictPattern ) { var newText : String = event.text.replace( restrictPattern, "" ); event.preventDefault(); textField.replaceSelectedText( newText ); } } private function keyFocusChange_handler( event : FocusEvent ) : void { if ( tabAllowed ) { event.preventDefault(); textField.replaceSelectedText( "\t" ); } } ]]> </mx:Script> </mx:TextArea> Then to restrict the input to uppercase letters, digits and TAB only, you would use something like this: <controls:RestrictedTextArea restrict="A-Z0-9\-\t"/> --- In [email protected], "Warren" <warrenony...@...> wrote: > > The tab character is in the restrict -- I checked -- but it isn't alowing > the tab character through. I may have to extend the textarea and use some > sort of regular expression to allow it. But I shouldn't have to according > to the docs. I should be able to specify ascii codes somehow. > > And I must apologize to all -- I oversimplified the original usage and led > some of you astray. I'm doing this to provide a bulk upload capability > into > a datagrid to meet a specific requirement. The user isn't entering the tab > character. They are cutting and pasting columns from Excel into the > textarea. When this happens, Excel automatically puts tabs (\t) between > the > cells and \n at the end of every row. I can easily parse the \t \r > combinations from the textarea into an array collection. So far it works > great if I don't restrict. I suppose I could eliminate offending > characters > when I parse but using the restrict was very elegant. It just cleaned > everything up in one shot. > > I hadn't really considered allowing the users to type in a tab. I'm kinda > glad I oversimplified -- you folks gave me some very good ideas on how to > handle that. > > ----- Original Message ----- > From: "Kerry Jordan" <kerry.d.jor...@...> > To: <[email protected]> > Sent: Thursday, June 10, 2010 7:43 AM > Subject: Re: [flexcoders] TextArea -- allow tab character in restrict > property > > > So using "A-Z0-9\- " didn't work? To what code did the " " character > equate? (That should be a tab character and not a space character...) > > Kerry > > On Thu, Jun 10, 2010 at 5:47 AM, Warren <warrenony...@...> wrote: > > > > sure -- if I could figure out how to indicate ascii character codes in > > the > > restrict clause. I've tried adding \x09 and \u0009 with no luck. > > > > ----- Original Message ----- > > From: Kerry Jordan > > To: [email protected] > > Sent: Wednesday, June 09, 2010 1:49 PM > > Subject: Re: [flexcoders] TextArea -- allow tab character in restrict > > property > > > > > > On Wed, Jun 9, 2010 at 1:36 PM, Warren <warrenony...@...> wrote: > > > I have a Flex 3 textarea with restrict = "A-Z0-9\-". I want to let > > > users > > > enter a tab cahracter but I can't figure out how to change the > > > restrict > > > property to allow it. > > > > > > > Couldn't you simply enter a tab between the restrict quotes (i.e., > > "A-Z0-9\- ")? Or maybe I'm missing something? > > > > Kerry > > > > > > > ------------------------------------ > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Alternative FAQ location: > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups > Links >

