-
restricting carriage returns in text input fields??
Does anyone know if it's possible to restrict hard returns in text input fields? I've tried something like this:
my_txt.restrict="^\u0013", and a bunch of variations thereof, but nothing seems to keep the Enter key from doing it's thing.
Second best would be to traverse through a string a user has entered and replace hard returns with a space or dash, but again I've had no luck looking for \n or \r. I've tried entering text and hard returns into a dynamic textfield set to input, but when I try this:
var n:Number = my_txt.indexOf("\n")...
trace("n: "+n) //traces "n: -1"
Anyone have any insight into this?
John
-
Modulator
What do you mean?
Do you just want them to write on one line?
There are properties you can change within the Flash Workspace.
As a Gamer, you play by the rules.
As a Programmer, you play as God.
-
No, I want the text field to wrap. But I need to disable hard returns because I'm sending the text up to the server, where it gets converted to XML and is stored in a database. Unfortunately, any text that has hard returns gets truncated after the return.
Example: I send this text to the server "Here is some text [hard return] I'm sending to the server."
When I later request that text from the server I get "Here is some text"
So I need to either strip hard returns from the text before I send it, or better yet, disable carriage returns altogether.
-
Modulator
Aah, okay. I see what you mean.
I've been trying to restrict the carriage return key for the last hour or so...no luck =_=
So I guess you'll have to resort to using a function to listen for when the carriage return is pressed, and stripping it.
Note: Carriage return is either decimal "13" or Hexidecimal "\u000D", although I have a sneaking suspicion that a function to strip the paragraph of carriage returns is gonna need something else...
Oh well, best of luck.
NOTE: I'll try to write a "CR stripping function", and if it works I'll post it here. Otherwise it's up to you ^_^
As a Gamer, you play by the rules.
As a Programmer, you play as God.
-
inputfield.addEventListener(Event.CHANGE, onChange);
private function onChange(e:Event):void {
if ( inputfield.text.charCodeAt(inputfield.text.length - 1) == 13 ) {
inputfield.text = inputfield.text.substr(0, inputfield.text.length - 1);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|